In Module Integration Test Example with different source location

In the previous example we had located the integration test classes into the same folder as the unit tests. Sometimes this might not represent your wishes. If you like you can put the integration test sources into a different folder like src/it/java.

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

The pom.xml for this integration test example must be changed to handle the supplemental source folder src/it/java. This can be simply achieved by using the Build Helper Maven Plugin. If you need to add supplemental resources for the integration tests you have to change the configuration accordingly. The following pom.xml snippet will show what you have to add.

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <id>add-test-source</id>
            <!--
                This will help m2eclipse to recognize the folder as source
                folder after update project configuration.
            -->
            <phase>process-resources</phase>
<!--            <phase>generate-test-sources</phase>-->
            <goals>
              <goal>add-test-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/it/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

Tip:

If you like to add the new source folder automatically to your Eclipse configuration you need to change the phase from generate-test-resources into process-resources. The result of this change is that you will see the src/it/java folder as source folder within in Eclipse after an Update Project Configuration as any other source folders. Furthermore it is achievable by changing the configuration of Eclipse.

The execution will be exactly the same as in the previous example. This can be done by calling mvn clean verify.

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
65
66
67
[INFO] Scanning for projects...
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building MaUI Test Guide :: Integration Test Example 1 0.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ it-test-example-1 ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ it-test-example-1 ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/maui/src/main/resources
[INFO]
[INFO] --- build-helper-maven-plugin:1.5:add-test-source (add-test-source) @ it-test-example-1 ---
[INFO] Test Source directory: /home/maui/src/it/java added.
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ it-test-example-1 ---
[INFO] Compiling 1 source file to /home/maui/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ it-test-example-1 ---
[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-1 ---
[INFO] Compiling 2 source files to /home/maui/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12:test (default-test) @ it-test-example-1 ---
[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.053 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-1 ---
[INFO] Building jar: /home/maui/target/it-test-example-1-0.1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-failsafe-plugin:2.12:integration-test (integration-test) @ it-test-example-1 ---
[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.061 sec
 
Results :
 
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
 
[INFO]
[INFO] --- maven-failsafe-plugin:2.12:verify (verify) @ it-test-example-1 ---
[INFO] Failsafe report directory: /home/maui/target/failsafe-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.000s
[INFO] Finished at: Sat May 25 18:45:37 CEST 2013
[INFO] Final Memory: 19M/149M
[INFO] ------------------------------------------------------------------------