2

I have a a unit test (ProductDaoTest.java) and an integration test (ProductDaoIT.java) in my maven application.

I would like to execute only the integration test during the mvn verify command call but the unit test also gets executed even after excluding it using the <exclude> tag in the maven-failsafe-plugin configuration.

How can I fix this problem?

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19.1</version> <configuration> <excludes> <exclude>**/*Test.java</exclude> </excludes> </configuration> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> 

Updated POM (with solution):

 <!-- For skipping unit tests execution during execution of IT's --> <profiles> <profile> <id>integration-test</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <!-- Skips UTs --> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <!-- Binding the verify goal with IT --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>2.19.1</version> <executions> <execution> <goals> <goal>integration-test</goal> <goal>verify</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>5000</port> <path>${project.artifactId}</path> </configuration> <executions> <execution> <id>start-tomcat</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <fork>true</fork> </configuration> </execution> <execution> <id>stop-tomcat</id> <phase>post-integration-test</phase> <goals> <goal>shutdown</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> 

mvn clean install - Runs only unit tests by default

mvn clean install -Pintegration-test - Runs only integration tests by default

1
  • Excluding the unit tests in failsafe does not make sense cause it has the naming schema: *IT.java so this configuration can be removed. You can use mvn verify -Dmaven.test.skip=true .... Commented Aug 15, 2016 at 16:03

1 Answer 1

2

In Maven, test step is before verify step in the lifecycle.
So it you don't skip this step, it is bound to execute.

If you want to skip test , either use -Dmaven.test.skip=tr‌​ue as khmarbaise suggested, either create a dedicated Maven profile for IT where you will ignore unit-tests in this way :

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> 

Generally, you create a Maven profile for integration tests, so if it is the case, gathering all the configuration in a place is better that scattering it.

Sign up to request clarification or add additional context in comments.

2 Comments

Was able to finally solve the problem with the use of profiles. Updated my question with answer above.
Good initiative. It could be useful to others.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.