In this article, we will learn and understand how to skip unit test while building maven based project using surefire plugin
One of the maven’s features is to run unit test automatically and if some of the test cases fail, then maven build fails
Irrespective of the unit test failure, we still need to move on to build the project successfully. In these circumstances, we have to suppress maven from running unit test for us which results in “BUILD FAILURE”
1. Skip unit test using surefire plugin
- If we need to suppress/disable running unit test for a particular project, configure “skipTests” tag to true of surefire plugin in pom.xml
pom.xml
<project>
[...]
<properties>
<skipTests>true</skipTests>
</properties>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
2. Skipping unit test from command line:
- You can skip unit test running below maven command
mvn install -DskipTests
Or
mvn install -Dmaven.test.skip=true
2.1 To be noted
- With above pom.xml configuration, by-default maven suppresses or disable running unit test
- But to re-enable them, use below maven command from CLI
mvn install -DskipTests=false
Useful Eclipse IDE shortcuts :
- Eclipse IDE – How to show line numbers ?
- Eclipse IDE – How to GO TO any line number directly ?
- Eclipse IDE – How to remove unused imports ?
- Eclipse IDE – How to clean project ?
- Eclipse IDE – How to build Java project automatically ?
- Eclipse IDE – How to comment and un-comment line & block ?
- Eclipse IDE – How to generate constructor using fields ?
- Eclipse IDE – How to generate getters and setters ?
- Eclipse IDE – How to search files ?
- Eclipse IDE – How to locate methods in Java file ?
- Eclipse IDE – How to open editor using CTRL + E ?
- Eclipse IDE – Java compiler compliance level issue
Related Articles:
- Apache Maven – Introduction
- Apache Maven – Install on Windows 7 OS
- Apache Maven – Settings.xml explanation
- Apache Maven – Proxy setting explanation
- Apache Maven – pom.xml explanation
- Apache Maven – Plugins explanation
- Apache Maven – Changing default Maven repository location in Windows 7 OS
- Apache Maven – Local, Central and Remote Repositories
- Apache Maven – Installing custom library into local repository
- Apache Maven – Transitive dependencies explanation
- Apache Maven – Exclusion of Transitive dependencies
- Apache Maven – Dependency Scopes
- Apache Maven – Skipping unit test using surefire plugin
- Apache Maven – Exclusions and Inclusions of unit test
- Apache Maven – offline execution
- Apache Maven – Co-ordinates explained
- Eclipse + Maven – Integration
- Eclipse + Maven – How to import Maven project with pom.xml ?
- Eclipse + Maven – Setting M2_REPO classpath variable in IDE
- Eclipse + Maven – M2_REPO is Non Modifiable
- Eclipse + Maven – Creating and exploring projects using archetypes
- Eclipse + Maven – Converting Web project to Maven project
- Eclipse + Maven – mvn eclipse:eclipse command
- Eclipse + Maven – Plugin execution not covered by lifecycle configuration
References:
- http://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-test.html
- http://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
- http://maven.apache.org/general.html#skip-test
Happy Coding !!
Happy Learning !!