When using Maven packaging, unit test packaging may fail and you need to skip unit tests.

Maven skips unit testing here are three ways.

Skip the test in command line mode

We can skip tests with two commands

  • mvn clean install -DskipTests
  • mvn clean install -Dmaven.test.skip=true

-dskiptests, does not execute test cases, but compiles test case classes to generate the corresponding class file to target/test-classes

-dmaven.test. skip=true, does not execute test cases, and does not compile test case classes

Using maven.test.skip skips not only running unit tests, but also compiling test code.

Using MVN package-dskiptests skips unit tests, but compilation continues.


2. Skip tests in pom.xml configuration

You can skip tests by adding the following configuration to pom.xml:

<build> <plugins> <! Plugin > <groupId>org.apache.maven.plugins</groupId> <artifactId> Maven-surefire-plugin </artifactId>  <configuration> <skip>true</skip>
                </configuration>
            </plugin>
       </plugins>
   <build>         

Copy the code


3. Skip the test in Idea configuration

Idea is our common development tool, and we often package it directly with Idea plug-ins. We can configure to skip testing.

1. Direct configuration

The Maven command bar toolbar has the icon shown below. This icon is Skip Tests. Click “Select” and then use “LifeStyle” package to skip the test.


2. Change the Maven configuration

  • Method 1: Open configuration, find Maven–>Runner, add == -dmaven.test. skip=true== in VM Option



  • Method 2: Runner–> Propertis select ==Skip tests==




Reference:

[1] : Maven skips compilation of test [2] : MVN skips compilation of test [3] : MVN skips compilation of test [4] : MVN skips compilation of test