Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
maven
communitycreator

How to skip unit tests in Maven

abhilash

Overview

Many times during the build stage of the Maven application, developers will have to skip the unit test cases. This shot covers how to skip the execution of the unit test cases during the build of the Maven application.

How to use maven.test.skip

Set the maven.test.skip property to true to ensure that the unit tests are not run during the build phase.

This can be done in two ways. They are as follows.

1. As command-line arguments

mvn clean install -Dmaven.test.skip=true

In the command above, maven.test.skip is passed as a command-line argument.

2. As a property in the pom.xml

<properties>
        <maven.test.skip>true</maven.test.skip>
</properties>

Here, the property is set to true via properties in pom.xml file.

How to use Maven profiles

We can use the Maven profile to skip the running of the unit test cases. We need to activate the profile during the Maven build process.

We create the following profile in the pom.xml file where we set the maven.test.skip property to true.

<profiles>
        <profile>
            <id>skiptest</id>
            <properties>
                <maven.test.skip>true</maven.test.skip>
            </properties>
        </profile>
</profiles>

We activate the profile above during the Maven build process as follows.

maven clean install -Pskiptest

RELATED TAGS

java
maven
communitycreator
RELATED COURSES

View all Courses

Keep Exploring