public class DbUnitRule extends Object implements org.junit.rules.MethodRule
@Rule which provides support for @DatabaseSetup,
@DatabaseTearDown and @ExpectedDatabase annotations.
The fields of the test class will inspected to locate the IDatabaseConnection or DataSource to use.
Generally, a single @Autowired field is expected. It is also possible to configure the connection
directly using the setDatabaseConnection(org.dbunit.database.IDatabaseConnection) and setDataSource(javax.sql.DataSource) methods.
Datasets are loaded using the FlatXmlDataSetLoader unless a loader is located from a field of the test class
or specifically configured.
Database operations are are lookup up using a DefaultDatabaseOperationLookup unless a
DatabaseOperationLookup is located from a field of the test class or specifically
configured.
| Modifier and Type | Class and Description |
|---|---|
protected class |
DbUnitRule.DbUnitTestContextAdapter |
| Constructor and Description |
|---|
DbUnitRule() |
| Modifier and Type | Method and Description |
|---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runners.model.FrameworkMethod method,
Object target) |
void |
setDatabaseConnection(org.dbunit.database.IDatabaseConnection connection)
Set the
IDatabaseConnection that will be used when running DBUnit tests. |
void |
setDatabaseOperationLookup(DatabaseOperationLookup databaseOperationLookup)
Set the
DatabaseOperationLookup that will be used to lookup DBUnit databsae operations. |
void |
setDataSetLoader(DataSetLoader dataSetLoader)
Set the
DataSetLoader that will be used to load IDataSets. |
void |
setDataSource(DataSource dataSource)
Set the
DataSource that will be used when running DBUnit tests. |
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
org.junit.runners.model.FrameworkMethod method,
Object target)
apply in interface org.junit.rules.MethodRulepublic void setDataSource(DataSource dataSource)
DataSource that will be used when running DBUnit tests. Note: Setting a data source will replace
any previously configured connection.dataSource - The data sourcepublic void setDatabaseConnection(org.dbunit.database.IDatabaseConnection connection)
IDatabaseConnection that will be used when running DBUnit tests. Note: Setting a connection will
replace any previously configured dataSource.connection - The connectionpublic void setDataSetLoader(DataSetLoader dataSetLoader)
DataSetLoader that will be used to load IDataSets.dataSetLoader - The data set loaderpublic void setDatabaseOperationLookup(DatabaseOperationLookup databaseOperationLookup)
DatabaseOperationLookup that will be used to lookup DBUnit databsae operations.databaseOperationLookup - the database operation lookupCopyright © 2013. All Rights Reserved.