Annotation Interface DbUnitConfig
DataFileLoader loads dataset files, how to obtain a tester via
DatabaseTesterFactory when no field supplies one, which
PrepAndExpectedTestCase implementation drives the prep/expected path,
DatabaseConfig properties, and the shared table-definition catalog.
For configuration shared across many test classes, compose one custom annotation
carrying @DbUnitTest, this annotation, and the lifecycle annotations, rather than
repeating them on every class:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
@DbUnitTest
@DbUnitConfig(dataFileLoader = FlatXmlDataFileLoader.class)
@DbUnitSetup(operation = DbUnitOperation.REFRESH)
public @interface AppDatabaseTest {}
- Since:
- 3.6.0
- Author:
- Jeff Jensen
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether the connection this executor resolves - for the prep/expected path, the row count check, or parameter injection - is closed after each test.Class<? extends DatabaseTesterFactory> ADatabaseTesterFactoryimplementation to reflectively instantiate (with its no-arg constructor) and ask to create theIDatabaseTesterto use, when neither aDbUnitTestCasenor aDbUnitTesterfield is declared.Class<? extends DataFileLoader> TheDataFileLoaderimplementation used to load everyDbUnitPrepandDbUnitExpecteddataset file, reflectively instantiated with its no-arg constructor.A classpath directory prefix applied to everyDbUnitPrepandDbUnitExpectedpath that neither starts with/nor is otherwise absolute, ahead of the test-class-package default.Class<? extends FailureHandler> TheFailureHandlerto hand verification failures to, in place of dbUnit's own default.booleanWhether the JUnit binding resolves a bareConnectionparameter on this test.Class<? extends PrepAndExpectedTestCase> ThePrepAndExpectedTestCaseimplementation to reflectively instantiate for the prep/expected path when noDbUnitTestCasefield supplies one already, via a constructor accepting(DataFileLoader, IDatabaseTester, boolean)- the same shapeDefaultPrepAndExpectedTestCaseitself has.InlineDatabaseConfigproperty name/value pairs to apply.Class<? extends DatabaseConfigPropertiesProvider> ADatabaseConfigPropertiesProviderimplementation to reflectively instantiate (with its no-arg constructor) and ask for theDatabaseConfigproperties to apply, for properties shared across several test classes.Class<?>[]One or more catalog classes to read sharedVerifyTableDefinitionconstants from, as the class-level default for every method'sDbUnitExpected.verifyDefinitions().
-
Element Details
-
dataFileLoader
Class<? extends DataFileLoader> dataFileLoaderTheDataFileLoaderimplementation used to load everyDbUnitPrepandDbUnitExpecteddataset file, reflectively instantiated with its no-arg constructor.On the prep/expected path (
DbUnitExpecteddeclared), a freshly-constructedprepAndExpectedTestCase()always receives this value through its constructor, regardless of implementation. ADbUnitTestCasefield injecting an already-built instance also receives it, but only when its type overridesPrepAndExpectedTestCase.setDataFileLoader(DataFileLoader)-DefaultPrepAndExpectedTestCasedoes; naming a non-default loader here for a different injected implementation fails fast withIllegalStateExceptioninstead of silently loading with whatever loader that instance was already constructed with.- Returns:
- The loader class; defaults to
FileExtensionDataFileLoader.
- Default:
org.dbunit.util.fileloader.FileExtensionDataFileLoader.class
-
databaseTesterFactory
Class<? extends DatabaseTesterFactory> databaseTesterFactoryADatabaseTesterFactoryimplementation to reflectively instantiate (with its no-arg constructor) and ask to create theIDatabaseTesterto use, when neither aDbUnitTestCasenor aDbUnitTesterfield is declared.- Returns:
- The factory class; the interface itself (the default) means "not set", falling through to the plain field auto-scan.
- Default:
org.dbunit.DatabaseTesterFactory.class
-
prepAndExpectedTestCase
Class<? extends PrepAndExpectedTestCase> prepAndExpectedTestCaseThePrepAndExpectedTestCaseimplementation to reflectively instantiate for the prep/expected path when noDbUnitTestCasefield supplies one already, via a constructor accepting(DataFileLoader, IDatabaseTester, boolean)- the same shapeDefaultPrepAndExpectedTestCaseitself has.In practice a
DefaultPrepAndExpectedTestCasesubclass, overriding a hook such assetUpDatabaseConfig(). A from-scratchPrepAndExpectedTestCasewould have to reimplement dataset loading, comparison, and cleanup, and override the six@DbUnitConfig-driven setters (setDataFileLoader,setFailureHandler,setDatabaseConfigProperties,setCloseConnectionAfterTest,setRowCountCheckOverride,clearRowCountCheckOverride) - one that does not fails fast at test time, naming the missing setter.- Returns:
- The test case class; defaults to
DefaultPrepAndExpectedTestCase.
- Default:
org.dbunit.DefaultPrepAndExpectedTestCase.class
-
properties
DbUnitProperty[] propertiesInlineDatabaseConfigproperty name/value pairs to apply.Mutually exclusive with
propertiesProvider(); setting both is rejected.On the prep/expected path (
DbUnitExpecteddeclared), only takes effect on aprepAndExpectedTestCase()whose type overridesPrepAndExpectedTestCase.setDatabaseConfigProperties(java.util.Properties)-DefaultPrepAndExpectedTestCasedoes. ADbUnitTestCasefield injecting a different implementation fails fast withIllegalStateExceptioninstead, since that path has no other route to the connection at all. On the setup/teardown path (noDbUnitExpected), this restriction does not apply - every value always reaches the tester's connection.On the prep/expected path, a
DefaultPrepAndExpectedTestCasesubclass that overridessetUpDatabaseConfig(DatabaseConfig)must callsuper.setUpDatabaseConfig(config)- the pre-3.6.0 way to configure aDatabaseConfig- or these values are silently dropped: they are applied through that samesetUpDatabaseConfig()hook. The extension logs a warning when it sees such an override together withproperties()/propertiesProvider(), since it cannot tell from reflection alone whether thesupercall is present.- Returns:
- The properties; empty (the default) applies none.
- Default:
{}
-
propertiesProvider
Class<? extends DatabaseConfigPropertiesProvider> propertiesProviderADatabaseConfigPropertiesProviderimplementation to reflectively instantiate (with its no-arg constructor) and ask for theDatabaseConfigproperties to apply, for properties shared across several test classes.Mutually exclusive with
properties(); setting both is rejected.Subject to the same restriction on the prep/expected path that
properties()documents.- Returns:
- The provider class; the interface itself (the default) means "not set".
- Default:
org.dbunit.database.DatabaseConfigPropertiesProvider.class
-
verifyDefinitions
Class<?>[] verifyDefinitionsOne or more catalog classes to read sharedVerifyTableDefinitionconstants from, as the class-level default for every method'sDbUnitExpected.verifyDefinitions(). SeeDbUnitExpectedfor how the two resolve independently and what "catalog" means.- Returns:
- The catalog classes; empty (the default) means "not set".
- Default:
{}
-
dataSetBaseDir
String dataSetBaseDirA classpath directory prefix applied to everyDbUnitPrepandDbUnitExpectedpath that neither starts with/nor is otherwise absolute, ahead of the test-class-package default.- Returns:
- The base directory; empty (the default) means "not set".
- Default:
""
-
failureHandler
Class<? extends FailureHandler> failureHandlerTheFailureHandlerto hand verification failures to, in place of dbUnit's own default.Only takes effect on a
prepAndExpectedTestCase()whose type overridesPrepAndExpectedTestCase.setFailureHandler(FailureHandler)-DefaultPrepAndExpectedTestCasedoes. ADbUnitTestCasefield injecting a different implementation fails fast withIllegalStateExceptioninstead, naming the implementation and this attribute, since a silent no-op here would otherwise leave the configured handler applied nowhere.- Returns:
- The failure handler class, reflectively instantiated with its no-arg constructor; the interface itself (the default) means "not set".
- Default:
org.dbunit.assertion.FailureHandler.class
-
closeConnectionAfterTest
boolean closeConnectionAfterTestWhether the connection this executor resolves - for the prep/expected path, the row count check, or parameter injection - is closed after each test.Set to
falsewhen theIDatabaseTestershares aCachingConnectionProvideracross test methods, so this test does not close a connection other tests still expect to reuse. The connection is also left open, regardless of this attribute, when the tester'sIOperationListenerisIOperationListener.NO_OP_OPERATION_LISTENER- the established, pre-existing signal that a tester's connection is managed elsewhere - so a connection already protected that way needs no explicitfalsehere.On the prep/expected path, a freshly constructed
prepAndExpectedTestCase()- noDbUnitTestCasefield supplies one already - always receives this value through its(DataFileLoader, IDatabaseTester, boolean)constructor, regardless of implementation. ADbUnitTestCasefield injecting an already-built instance receives it too, but only when its type overridesPrepAndExpectedTestCase.setCloseConnectionAfterTest(boolean)-DefaultPrepAndExpectedTestCasedoes; setting this tofalsefor a different injected implementation logs a warning rather than failing fast, since - unlike the other@DbUnitTestCase-injected setters here - this executor's own connection (for the row count check or parameter injection) still honors the value regardless; only that test case's own connection handling might not.- Returns:
- True to close the connection after each test; defaults to true.
- Default:
true
-
injectConnectionParameter
boolean injectConnectionParameterWhether the JUnit binding resolves a bareConnectionparameter on this test. Defaulttrue.Set to
falsewhen another extension on the same test - Spring'sSpringExtension, Testcontainers, a JPA or JDBC test harness - also resolvesjava.sql.Connection: JUnit Jupiter rejects twoParameterResolvers competing for one parameter with "discovered multiple competing ParameterResolvers", and dbUnit yields the commonConnectiontype rather than force the other extension to. The dbUnit-specificIDatabaseConnectionparameter is still resolved regardless - no other framework claims that type - so inject that and call itsgetConnection()for the JDBC connection.- Returns:
- True to resolve a
java.sql.Connectionparameter; defaults to true.
- Default:
true
-