DbUnit includes a comprehensive test suite. Most of the tests are unit tests , and do not rely on any particular database environment. Some of the tests are integration tests , and can test DbUnit functionality against a particular database.
Maven profiles control which database environment is in use for a particular test run.
The default profile runs the tests using an HSQLDB in-memory database, which does not require a database server.
Other profiles run against server-based database products.
For example, to run the tests using the DbUnit Oracle10DataTypeFactory and the Oracle 10 JDBC driver for JDK 1.4, use this command:
mvn clean test -Poracle10-ojdbc14
List all profiles using this command:
mvn help:all-profiles
Each database is configured by properties and dependencies. The properties relate to standard JDBC connection parameters, and the dependencies cover the database-specific JDBC driver.
The properties include:
These properties are all configured with defaults per test profile. You can override these defaults in ~/.m2/settings.xml:
<settings>
<profiles>
<profile>
<id>oracle-ojdbc14</id>
<properties>
<dbunit.profile.url>jdbc:oracle:thin:@myhost:1521:mysid</dbunit.profile.url>
</properties>
</profile>
</profiles>
</settings>
Nothing special is required.
Run the full test suite, including integration tests, with this command:
mvn clean test
These values are the defaults configured in the project. If you use different values, you will need to override the properties in your Maven settings.xml.
This should create the DbUnit test schema in your Oracle database. You are now ready to run tests.
Run the full test suite, including integration tests, with one of these commands:
mvn clean test -Poracle-ojdbc14 mvn clean test -Poracle-ojdbc6 mvn clean test -Poracle10-ojdbc14 mvn clean test -Poracle10-ojdbc6
sudo -u postgres psql <<EOF CREATE USER dbunit WITH PASSWORD 'dbunit'; CREATE DATABASE dbunit OWNER dbunit; \q EOF
These values are the defaults configured in the project. If you use different values, you will need to override the properties in your Maven settings.xml.
This should create the DbUnit test schema in your PostgreSQL database. You are now ready to run tests.
Run the full test suite, including integration tests, with this command:
mvn clean test -Poracle-default,postgresql
Note: currently the oracle-default profile is required, along with the postgresql profile, to ensure all JARs required on the compile-time classpath in Maven.
mysql -uroot -p <<EOF # (enter database root password) CREATE DATABASE dbunit; GRANT ALL ON dbunit.* TO dbunit@localhost IDENTIFIED BY "dbunit"; EOF
These values are the defaults configured in the project. If you use different values, you will need to override the properties in your Maven settings.xml. If you need to connect remotely to your database your need to specify the client host name. You may also need to adjust your MySQL configuration to permit remote connection.
mysql -hmysql_host -Ddbunit -udbunit -pdbunit <src/sql/mysql.sql
This should create the DbUnit test schema in your MySQL database. You are now ready to run tests.
Run the full test suite, including integration tests, with this command:
mvn clean test -Poracle-default,mysql
Note: currently the oracle-default profile is required, along with the mysql profile, to ensure all JARs required on the compile-time classpath in Maven.
Nothing special is required.
Run the full test suite, including integration tests, with this command:
mvn clean test -Poracle-default,derby
Note: currently the oracle-default profile is required, along with the derby profile, to ensure all JARs required on the compile-time classpath in Maven.