Jakub is a Java EE developer since 2005 and occasionally a project manager, working currently with Iterate AS. He's highly interested in developer productivity (and tools like Maven and AOP/AspectJ), web frameworks, Java portals, testing and performance and works a lot with IBM technologies. A native to Czech Republic, he lives now in Oslo, Norway. Jakub is a DZone MVB and is not an employee of DZone and has posted 154 posts at DZone. You can read more from them at their website. View Full User Profile

DbUnit Express 1.3 is Even Easier to Use and Still Better

09.13.2011
| 4143 views |
  • submit to reddit

The DbUnit Express 1.3.0 (a thin wrapper around DbUnit to speed up DB testing) released recently 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.

See the updated project page and example tests.

Other changes of interest:

  1. The project was now officially renamed to dbunit-express (and root package changed to net.jakubholy.dbunitexpress), so update your Maven dependencies and code
  2. Upgraded to latest DbUnit (2.4.8, was 2.4.7)
  3. 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
  4. Added EmbeddedDbTesterRule which can call its onSetup automatically under JUnit 4
  5. Added setDataSet(String) that tries to find a file of the given name in testData/ or on the classpath and loads it
  6. When there is a FileNotFoundException for the ddl, report the working directory, check if testData/ self exists
  7. Added comment to onTearDown() saying that it does nothing and thus doesn’t need to be called, updated test classes accordingly
  8. Added SimpleNonExtendingEmbeddedDbJUnit4Test to show usage with JUnit 4
  9. 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
  10. Added method findConfigFile(name) to simplify custom DataSet creation, location of DDL files etc.
  11. 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
PS: As you might have noticed, the project was migrated to GitHub because I couldn’t stand Subversion anymore. Its inability to deal with deleted folders was killing me.

 

From http://theholyjava.wordpress.com/2011/09/04/dbunit-express-1-3-is-even-easier-to-use-and-still-better/

Published at DZone with permission of Jakub Holý, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: