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
*IT.javaso this configuration can be removed. You can usemvn verify -Dmaven.test.skip=true....