Project

General

Profile

Actions

IntegrationTestWriting » History » Revision 3

« Previous | Revision 3/16 (diff) | Next »
Andreas Kohlbecker, 03/05/2013 02:11 PM



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

Related pages:


CdmTransactionalIntegrationTest

  • 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:

@Test
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
public void testArea_area() throws FileNotFoundException {
  // your test
}

Generating test data

Updated by Andreas Kohlbecker about 11 years ago · 3 revisions