Annotation Interface DbUnitTearDown
A method-level annotation overrides a class-level annotation; the class annotation is
inherited by subclasses. Unlike DbUnitSetup, teardown has no dataset counterpart:
the dataset already prepared - the union of the prep and expected data, when
DbUnitExpected is present - is what the operation runs against. Declaring an extra
table to tear down is done by listing it, empty, in the prep dataset instead.
On the prep/expected path (DbUnitExpected declared), this operation is applied to
the resolved IDatabaseTester, which only reaches the actual teardown call when the
test case reads its own teardown 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 — delete all rows after each test:
@DbUnitTest
@DbUnitPrep("/datasets/orders.json")
@DbUnitTearDown(operation = DbUnitOperation.DELETE_ALL)
class OrderRepositoryTest {
IDatabaseTester databaseTester;
OrderRepositoryTest() throws ClassNotFoundException {
databaseTester = new JdbcDatabaseTester("driver", "url", "user", "pass");
}
@Test
void testPlaceOrder() { ... }
}
- Since:
- 3.6.0
- Author:
- Jeff Jensen
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe database operation to apply during teardown.
-
Element Details
-
operation
DbUnitOperation operationThe database operation to apply during teardown.- Returns:
- The teardown operation; defaults to
DbUnitOperation.NONE.
- Default:
NONE
-