In Module Integration Test Example

If you like to get your integration tests running you have to follow the naming conventions which are defined by the Maven Failsafe Plugin.

We have now changed the contents of our simple unit test project and added a supplemental class BitMaskIT.java which obviously is the integration test and follows the above naming conventions.

In this case we have put the integration test in parallel to the usual unit test class. This is usually only reasonable if you have a single module.

.
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- com
    |           `-- soebes
    |               `-- maui
    |                   `-- it
    |                       `-- BitMask.java
    `-- test
        `-- java
            `-- com
                `-- soebes
                    `-- maui
                        `-- it
                            |-- BitMaskIT.java
                            `-- BitMaskTest.java

The pom.xml for the integration test example has one particular enhancement in comparison to the original unit test example. The Maven Failsafe Plugin has been bound to the integration-test life-cycle-phase with its integration-test goal and the verify goal of the plugin has been bound to the verify life-cycle-phase of Maven.

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-failsafe-plugin</artifactId>
  <version>2.12</version>
  <executions>
    <execution>
      <id>integration-test</id>
      <goals>
        <goal>integration-test</goal>
      </goals>
    </execution>
    <execution>
      <id>verify</id>
      <goals>
        <goal>verify</goal>
      </goals>
    </execution>
  </executions>
</plugin>

If you like to execute the integration tests as well as the unit tests you can simply call mvn verify which includes the package phase and of course the integration-test phase. The Maven Failsafe Plugin will be called after the unit test and will execute the integration test in the BitMaskIT.java class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[INFO] Scanning for projects...
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building MaUI Test Guide :: Integration Test Example 0.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ it-test-example ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ it-test-example ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/maui/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ it-test-example ---
[INFO] Compiling 1 source file to /home/maui/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ it-test-example ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/maui/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ it-test-example ---
[INFO] Compiling 2 source files to /home/maui/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ it-test-example ---
[INFO] Surefire report directory: /home/maui/target/surefire-reports
 
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.soebes.maui.it.BitMaskTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.055 sec
 
Results :
 
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
 
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ it-test-example ---
[INFO] Building jar: /home/maui/target/it-test-example-0.1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-failsafe-plugin:2.12:integration-test (integration-test) @ it-test-example ---
[INFO] Failsafe report directory: /home/maui/target/failsafe-reports
 
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.soebes.maui.it.BitMaskIT
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.063 sec
 
Results :
 
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
 
[INFO]
[INFO] --- maven-failsafe-plugin:2.12:verify (verify) @ it-test-example ---
[INFO] Failsafe report directory: /home/maui/target/failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.024s
[INFO] Finished at: Sat May 25 18:45:28 CEST 2013
[INFO] Final Memory: 17M/258M
[INFO] ------------------------------------------------------------------------