IntegrationTestWriting » History » Version 4

« Previous - Version 4/14 (diff) - Next » - Current version
Andreas Kohlbecker, 03/05/2013 02:13 PM

How to write IntegrationTests and how to generate test data for them

Related pages:


  • In most cases you may want your test to be subclass of CdmTransactionalIntegrationTest

    • After a test method is run the transaction is usuallay rolled back.
    • If you need something to be really persisted into the data base call the commitAndStartNewTransaction()

method after the service.saveOrUpdate(Someting)

!dbUnit test data

Unitils profides integation with DbUnit wich support for testing with databases and loading of DbUnit data sets. DbUnit is a JUnit extension (also usable with Ant) targeted at database-driven projects that, among other things, puts your database into a known state between test runs. This is an excellent way to avoid the myriad of problems that can occur when one test case corrupts the database and causes subsequent tests to fail or exacerbate the damage.

Test dependencies and load strategy

Even if DbUnit should turn your database into a known and controlled state it can happen that the database contains leftovers from previous tests. In order to explicitly wipe out all potential remains you can in case use specific load strategy class, the CleanSweepInsertLoadStrategy which will provide you a really virgin database:

public void testArea_area() throws FileNotFoundException {
  // your test

Generating test data

Add picture from clipboard (Maximum size: 40 MB)