Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Maven is it possible to keep integration tests in a separate folder from unit tests?

On the Maven and Integration Testing page it says:

The Future Rumor has it that a future version of Maven will support something like src/it/java in the integration-test phase, in addition to src/test/java in the test phase.

but that was back in 2011-12-11. Has this happened yet?

In this answer to "Run maven test not in default src/test/java folder" it mentions setting the <testSourceDirectory>, is their some way of doing this just for integration test (ie. the integration-test phase)?

I'm looking to use the Maven FailSafe plugin and avoid renaming a bunch of integration tests or using the still experimental JUnit @Categories.

like image 447
Sled Avatar asked Jul 25 '13 17:07

Sled


People also ask

Where do you keep integration tests?

In general: yes, you should put integration tests and unit tests into different folders. Often, programmers don't draw a clear line between these two kinds of tests and just write whatever kind of test is useful. But integration tests tend to be slower, because they often involve: Database queries.

Should integration tests be in separate project?

The integration tests for the components of a single project should be within the project. The tests testing the integration of multiple projects with each other should be a separate project.

Does mvn test run integration tests?

The Maven build lifecycle now includes the "integration-test" phase for running integration tests, which are run separately from the unit tests run during the "test" phase. It runs after "package", so if you run "mvn verify", "mvn install", or "mvn deploy", integration tests will be run along the way.

Can Maven be integrated with Junit test framework?

Junit Framework can be integrated with Eclipse, Ant and Maven, but in this article we will be using Maven.


1 Answers

You can put the IT'ss into different folder like this:

. |-- 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 following is needed to make then folders known to the compiler etc.

<plugin>   <groupId>org.codehaus.mojo</groupId>   <artifactId>build-helper-maven-plugin</artifactId>   <version>1.5</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> 

The following is needed to really run the IT's:

<plugin>   <groupId>org.apache.maven.plugins</groupId>   <artifactId>maven-failsafe-plugin</artifactId>   <version>2.15</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> 

This means you can have the integration within the same module which has the disadvantage that running the integration tests use the same resources as the unit tests. A better solution would be to create a separate maven module where you can put the integration tests into the usual folder src/test/java etc. and only configure the maven-failsafe-plugin.

like image 115
khmarbaise Avatar answered Sep 22 '22 07:09

khmarbaise