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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption
  • 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

Trending

  • Microsoft Fabric Throttling: Diagnose Before You Scale
  • LangChainGo vs Genkit Go: Where Genkit Shines
  • One Database, Two Models: Building AI-Friendly Java Applications With MySQL JSON Duality Views
  • ScyllaDB in Enterprise Java: High-Performance NoSQL With Eclipse JNoSQL

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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
·
Dec. 21, 18 · Code Snippet
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
40.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Testing Java and Spring Applications With Kotlin: Low-Risk to Adoption
  • 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

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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