Annotation Interface DbUnitRowCountCheck
org.dbunit.database.rowcount.RowCountCheck) on for a
class or a method, with an exclude list: before the test it snapshots every table's row
count, after teardown it snapshots again, and it fails the test when any count moved. That
catches a table the test forgot to list for teardown - whose rows survive and break a later
test - and equally a reference table it wrongly listed, whose count went down.
enabled() defaults to true so that writing the bare annotation means
"on". It exists for the override direction: a class-level check with one method that
legitimately leaves rows behind - a test asserting that an audit trail persists, say -
writes @DbUnitRowCountCheck(enabled = false) on that method rather than losing the
check for the whole class.
Precedence, highest first:
- The
-Ddbunit.rowCountChecksystem property, when present - wins outright, in both directions, so it can force-enable across a CI run and force-disable locally without editing code. - This annotation - method level, else class level.
DatabaseConfig.FEATURE_ROW_COUNT_CHECK.- Default
false.
A method-level annotation overrides a class-level one wholesale, exclude()
included - the same rule as every other annotation in this family. A method that wants one
extra exclusion beyond the class-level ones has to repeat them; this is deliberate, since
merging would make "why is this table still excluded?" answerable only by reading two
declarations.
On the prep/expected path (DbUnitExpected declared), this annotation only
overrides the resolved check when the test case resolves to a
DefaultPrepAndExpectedTestCase - the only PrepAndExpectedTestCase
implementation exposing a setter for it; a DbUnitTestCase field injecting a
different implementation fails fast with IllegalStateException instead, since a
silent no-op here would otherwise leave the check never running for this test at all. On
the setup/teardown path (no DbUnitExpected), this restriction does not apply - the
check runs directly against the connection regardless of test case type.
- Since:
- 3.6.0
- Author:
- Jeff Jensen
-
Optional Element Summary
Optional Elements
-
Element Details
-
enabled
boolean enabledWhether the check is enabled.- Returns:
- True to enable the check; defaults to true.
- Default:
true
-
exclude
String[] excludeTable name patterns to exclude from the check.- Returns:
- The excluded table name patterns; empty (the default) excludes none.
- Default:
{}
-