DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Web App Load Testing Using Maven Plugins for Apache JMeter, and Analyzing the Results
  • Integrate Cucumber in Playwright With Java
  • Test Automation: Maven Profiles and Parallelization in Azure Pipelines Using IaaS
  • Agentic Testing: Moving Quality From Checkpoint to Control Layer

Trending

  • Feature Flag Debt: Performance Impact in Enterprise Applications
  • GenAI Implementation Isn't Magic — It’s a Lifecycle
  • Why Stable RAG Answers Can Still Hide Unstable Evidence
  • Jakarta EE 12: Entering the Data Age of Enterprise Java
  1. DZone
  2. Coding
  3. Java
  4. Maven Skipping Tests

Maven Skipping Tests

In this quick article, we will look into different ways to skip tests in maven applications.

By 
Ramesh Fadatare user avatar
Ramesh Fadatare
·
Dec. 21, 18 · Code Snippet
Likes (8)
Comment
Save
Tweet
Share
39.9K Views

Join the DZone community and get the full member experience.

Join For Free

Sometimes, we need to disable JUnit test cases written in Maven projects. When we build a Maven package, by default, Maven will execute the JUnit test cases.

Skipping Tests

If you are using Maven-surefire-plugin in your pom.xml, then it's easy to skip running the tests for a particular project and set the skipTests property to true.

<project>
  [...]

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
  [...]

</project>


From the Command Line

You can also skip the tests via the command line by executing the following command:

mvn install -DskipTests


If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe, and the Compiler Plugin.

mvn install -Dmaven.test.skip=true


Skipping by Default

If you want to skip tests by default, but also want the ability to re-enable tests from the command line, you need to go via a properties section in the pom:

<project>
  [...]

    <properties>
        <skipTests>true</skipTests>
    </properties>
  [...]

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <skipTests>${skipTests}</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
  [...]

</project>


This will allow you to run with tests disabled by default and to run them with this command:

mvn install -DskipTests=false


The same can be done with the "skip" parameter and other booleans on the plugin.

You can learn maven in-depth here. Happy coding !!

Testing Apache Maven

Published at DZone with permission of Ramesh Fadatare. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Web App Load Testing Using Maven Plugins for Apache JMeter, and Analyzing the Results
  • Integrate Cucumber in Playwright With Java
  • Test Automation: Maven Profiles and Parallelization in Azure Pipelines Using IaaS
  • Agentic Testing: Moving Quality From Checkpoint to Control Layer

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook