The DbUnit Express 1.3.0 (a thin wrapper around DbUnit to speed up DB testing) released today introduces features that make it even easier to write a DB unit test, the most interesting ones are the introduction of EmbeddedDbTesterRule which can automatically execute its onSetup thanks to JUnit’s @Rule (example) and the addition of setDataSet(fileName), which searches for a data set file of the given name on the classpath etc. and loads it.
Other changes of interest:
- The project was now officially renamed to dbunit-express (and root package changed to net.jakubholy.dbunitexpress), so update your Maven dependencies and code
- Upgraded to latest DbUnit (2.4.8, was 2.4.7)
- Added slf4j-simple to dependencies so that users don’t need to do it themselves anymore – those who don’t want it may just exclude it
- Added EmbeddedDbTesterRule which can call its onSetup automatically under JUnit 4
- Added setDataSet(String) that tries to find a file of the given name in testData/ or on the classpath and loads it
- When there is a FileNotFoundException for the ddl, report the working directory, check if testData/ self exists
- Added comment to onTearDown() saying that it does nothing and thus doesn’t need to be called, updated test classes accordingly
- Added SimpleNonExtendingEmbeddedDbJUnit4Test to show usage with JUnit 4
- When it is detected in onSetup() that the test database likely isn’t initialized, we advice to use Db Creator and report the current working directory
- Added method findConfigFile(name) to simplify custom DataSet creation, location of DDL files etc.
- Added DatabaseCreator.loadDdl(name) to load an additional DDL, you can also use new DatabaseCreator().setDdlFile(“fileOnClasspathOrInTestData.ddl”).doCreateAndInitializeTestDb() to init the DB from a custom DDL