Tuesday, 24 March 2015

How to skip integration test in maven build ?

Its not so easy when I was trying with all the possible and lost my 3 hours of valuable time. Its really very pathetic when you are trying to do something and its not happening within your time period....

This happens me when I was trying to build without the integration tests only. My scenario was to skip only integration tests ,but it must execute the unit test cases. I gooooogle almost many links but no luck , but finally the luck clicks and it works for me with below pom.xml configuration.


Add the below tag into you 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 <exclude> tag and mentioned any test class you want to skip.If your java class name contains *ITest.java (i.e. MyMethodITest.java)

<exclude>**/*IT*.java</exclude>

or 

<exclude>**/*AnyTestClasses.java</exclude>



Not only integration test you can skip any classes over here, but you need to configure the pom.xml properly.And in the maven command you can use below command as normal (i.e. mvn clean install)


Note - Be careful about the version, because it may not work for all version.

I hope it will help you all.