Project

General

Profile

IntegrationTestWriting » History » Revision 2

Revision 1 (Andreas Kohlbecker, 03/05/2013 01:41 PM) → Revision 2/16 (Andreas Kohlbecker, 03/05/2013 02:09 PM)

{{>toc}} 


 ----- 


 # How to write [[IntegrationTests]] and how to generate test data for them 


 Related pages: 

 * [[IntegrationTest|IntegrationTests - Testing java code using Maven and Unitils]] 




 ---- 



 ### 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.  



 ### dbUnit test data 


 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 
 } 
 ~~~