Reputation: 918
i m upgrading a project that contain only integration test wrote in JAVA.
Now we are going to write unit test, so i decide to create src/it/java folder to put all existing tests and wrote new unit test in src/test/java
I have use surfire and build-helper to do that.
in command line i can run
mvn clean install and only src/test/java directory are read for test
when i m doing
mvn -Pintegration-test clean install i see that test in src/it/java are read for test
so all work fine in command line.
Now i would like to import my project on eclipe. And when i m doing that only src/test/java is use as source folder. How can i set up pom.xml to have src/test/java and src/it/java as source folder?
**here is my builder plugin conf
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>process-resources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
thanks a lot!
Upvotes: 4
Views: 2695
Reputation: 97487
There are in general three ways of solving such problem.
Using a separate folder for integration tests as you already decided to use.
.
|-- 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
To get this working correctly in Eclipse you need to use the build-helper-maven-plugin which you already suggested:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-test-source</id>
<!--
This will help m2eclipse to recognize the folder as source
folder after update project configuration.
Based on comment updated.
-->
<phase>validate</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/it/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
But as you can see this takes several supplemental configuration in your pom file.
Apart from the above the usage of maven-surefire-plugin for integration tests is simply wrong, cause maven-surefire-plugin is intended for unit tests and not for integration tests so better is to go with maven-failsafe-plugin for integration tests.
Best is to following the naming conventions for unit and integration tests. In maven-surefire-plugin the unit tests follow the following convention:
- *Test.java
- *TestCase.java
- Test*.java
whereas the integration tests in maven-failsafe-plugin follow the following convention:
- *IT.java
- *ITCase.java
- IT*.java
.
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- com
| `-- soebes
| `-- maui
| `-- it
| `-- BitMask.java
`-- test
`-- java
`-- com
`-- soebes
`-- maui
`-- it
|-- BitMaskIT.java
`-- BitMaskTest.java
But sometimes much more better to make a separate module which contains only the integration tests to separate them from the unit tests. This might be helpfull if the integration tests have different configuration than the unit tests.
So making the structure like this:
+-- root (pom.xml)
+--- mod-it (pom.xml)
+--- mod-core (pom.xml)
You should follow the naming convention in the mod-it
to use the maven-failsafe-plugin
and correctly execute integration tests in the integration-test
phase of the maven
build life-cycle.
Upvotes: 8
Reputation: 66
You will need to add the src/it/java folder manually in Eclipse via:
Project Properties -> Java Build Path -> Source tab -> Add Folder.
Upvotes: -2