Annotation Interface DbUnitPrep
A method-level annotation overrides a class-level annotation on a per-test basis; the
class annotation is inherited by subclasses. Pair with DbUnitSetup only when a
setup operation other than the default
DbUnitOperation.CLEAN_INSERT is needed - see
DbUnitSetup for why the two are separate annotations.
Each path is resolved to an absolute classpath resource: a path already starting with
/ is used as-is; otherwise it is resolved relative to the test class's package, or
to DbUnitConfig#dataSetBaseDir() when that is set. The file format is inferred from
the extension by the configured DataFileLoader - see DbUnitConfig.dataFileLoader().
Example:
@DbUnitTest
class UserRepositoryTest {
IDatabaseTester databaseTester;
UserRepositoryTest() throws ClassNotFoundException {
databaseTester = new JdbcDatabaseTester("driver", "url", "user", "pass");
}
@Test
@DbUnitPrep("/datasets/users.xml")
void testFindAll() { ... }
}
- Since:
- 3.6.0
- Author:
- Jeff Jensen
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<? extends DataSetPathsProvider> ADataSetPathsProviderimplementation to reflectively instantiate and ask for the prep dataset paths, for a path list shared across several test classes.String[]Classpath resource paths for the prep dataset files to load.
-
Element Details
-
value
String[] valueClasspath resource paths for the prep dataset files to load.Mutually exclusive with
provider(); setting both is rejected.- Returns:
- Zero or more dataset resource paths.
- Default:
{}
-
provider
Class<? extends DataSetPathsProvider> providerADataSetPathsProviderimplementation to reflectively instantiate and ask for the prep dataset paths, for a path list shared across several test classes.Mutually exclusive with
value(); setting both is rejected. The provider returningnullor an empty array is rejected too - it is wired to supply paths, so supplying none is a misconfiguration; drop@DbUnitPrepfor a test that needs no dataset.- Returns:
- The provider class; the interface itself (the default) means "not set".
- Default:
org.dbunit.util.fileloader.DataSetPathsProvider.class
-