How to Skip Integration Tests in Maven but Execute Unit Tests
It was not so easy when I was trying all the possible options and lost 3 hours of my valuable time. It is really very frustrating when you are trying to do something and it is not happening within your expected time.
This happened to me when I was trying to build the project without executing the integration tests. My scenario was to skip only the integration tests, but the unit test cases must still be executed.
I Googled almost many links, but had no luck. Finally, the solution worked for me with the below pom.xml configuration.
Add the below tag into your pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
Here you can use the <exclude> tag and mention any test class pattern that you want to skip.
For example, if your Java class name contains ITest.java (i.e. MyMethodITest.java):
<exclude>**/*IT*.java</exclude>Or:
<exclude>**/*AnyTestClasses.java</exclude>
Not only integration tests, you can skip any test classes using the <exclude> tag, but you need to configure the pom.xml properly.
In the Maven command, you can use the normal command as below:
mvn clean install
Note: Be careful about the plugin version because the configuration may behave differently with different versions. Make sure the version you are using supports the configuration you need.