Annotation Interface DbUnitSetup
DbUnitPrep for the dataset to apply it to.
A method-level annotation overrides a class-level annotation on a per-test basis; the
class annotation is inherited by subclasses. Declaring only DbUnitPrep is the
common case: operation() defaults to DbUnitOperation.CLEAN_INSERT already,
so most tests never need this annotation at all.
Data (DbUnitPrep) and operation (DbUnitSetup) are deliberately separate
annotations rather than one fused annotation, so a class-level operation survives a
method-level DbUnitPrep instead of silently reverting to the default the moment a
method declares its own files.
On the prep/expected path (DbUnitExpected declared), this operation is applied to
the resolved IDatabaseTester, which only reaches the actual setup call when the test
case reads its own setup operation from that same tester the way
DefaultPrepAndExpectedTestCase does. A DbUnitTestCase field
injecting a different implementation that manages its own tester internally leaves this
annotation silently unapplied there.
Example — a class-wide DbUnitOperation.REFRESH operation, with each test method
naming its own prep file:
@DbUnitTest
@DbUnitSetup(operation = DbUnitOperation.REFRESH)
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 ElementDescriptionThe database operation to apply during setup.
-
Element Details
-
operation
DbUnitOperation operationThe database operation to apply during setup.- Returns:
- The setup operation; defaults to
DbUnitOperation.CLEAN_INSERT.
- Default:
CLEAN_INSERT
-