Project

General

Profile

IntegrationTestWriting » History » Version 2

Andreas Kohlbecker, 03/05/2013 02:09 PM

1 1 Andreas Kohlbecker
{{>toc}}
2 1 Andreas Kohlbecker
3 1 Andreas Kohlbecker
4 1 Andreas Kohlbecker
-----
5 1 Andreas Kohlbecker
6 1 Andreas Kohlbecker
7 1 Andreas Kohlbecker
# How to write [[IntegrationTests]] and how to generate test data for them
8 1 Andreas Kohlbecker
9 1 Andreas Kohlbecker
10 1 Andreas Kohlbecker
Related pages:
11 1 Andreas Kohlbecker
12 1 Andreas Kohlbecker
* [[IntegrationTest|IntegrationTests - Testing java code using Maven and Unitils]]
13 2 Andreas Kohlbecker
14 2 Andreas Kohlbecker
15 2 Andreas Kohlbecker
16 2 Andreas Kohlbecker
17 2 Andreas Kohlbecker
----
18 2 Andreas Kohlbecker
19 2 Andreas Kohlbecker
20 2 Andreas Kohlbecker
21 2 Andreas Kohlbecker
### CdmTransactionalIntegrationTest
22 2 Andreas Kohlbecker
23 2 Andreas Kohlbecker
24 2 Andreas Kohlbecker
* In most cases you may want your test to be subclass of `CdmTransactionalIntegrationTest` 
25 2 Andreas Kohlbecker
26 2 Andreas Kohlbecker
  * After a test method is run the transaction is usuallay rolled back.
27 2 Andreas Kohlbecker
28 2 Andreas Kohlbecker
  * If you need something to be really persisted into the data base call the `commitAndStartNewTransaction()` 
29 2 Andreas Kohlbecker
30 2 Andreas Kohlbecker
  method after the `service.saveOrUpdate(Someting)` 
31 2 Andreas Kohlbecker
32 2 Andreas Kohlbecker
33 2 Andreas Kohlbecker
34 2 Andreas Kohlbecker
### dbUnit test data
35 2 Andreas Kohlbecker
36 2 Andreas Kohlbecker
37 2 Andreas Kohlbecker
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. 
38 2 Andreas Kohlbecker
39 2 Andreas Kohlbecker
40 2 Andreas Kohlbecker
41 2 Andreas Kohlbecker
### dbUnit test data
42 2 Andreas Kohlbecker
43 2 Andreas Kohlbecker
44 2 Andreas Kohlbecker
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:
45 2 Andreas Kohlbecker
46 2 Andreas Kohlbecker
~~~
47 2 Andreas Kohlbecker
@Test
48 2 Andreas Kohlbecker
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
49 2 Andreas Kohlbecker
public void testArea_area() throws FileNotFoundException {
50 2 Andreas Kohlbecker
  // your test
51 2 Andreas Kohlbecker
}
52 2 Andreas Kohlbecker
~~~
53 2 Andreas Kohlbecker
54 2 Andreas Kohlbecker
55 2 Andreas Kohlbecker
 
Add picture from clipboard (Maximum size: 40 MB)