Unit Test – Maven skip test with SpringBoot

In the tutorial, JavaSampleApproach will show you how to work with Maven skip test and SpringBoot.

Related posts:
@DataJPATest with Spring Boot
Spring Boot Unit Test for Spring MVC Controller

I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.6RELEASE

II. Skip Test with Maven & SpringBoot

1. Preparation

Firstly, using SpringToolSuite to create a SpringBoot project as below:

SpringBoot Maven Skip Test - project structure

Then modify SpringMavenSkipTestApplicationTests class as below:

2. Skip Test

2.1 skipTests & maven.test.skip

We can control the testing when running Maven build through skipTests or maven.test.skip properties.

How to use? -> We use them via commandlines: mvn clean install -DskipTests or mvn clean install -Dmaven.test.skip=true

What is the difference between them?

maven.test.skip property will skip compiling and skip running the tests. It is honored by Surefire, Failsafe and the Compiler Plugin.

SpringBoot Maven Skip Test - maven.test.skip=true

skipTests is the feature of Surefire. It will complile BUT NOT run the tests.

SpringBoot Maven Skip Test - skipTests

2.2 skipping by default

We set properties {skipTests, maven.test.skip} in the pom.xml file.

with maven.test.skip

To enable test, we use commandline: mvn clean install -Dmaven.test.skip=false.

with skipTests

To enable test, we use commandline: mvn clean install -DskipTests=false.


-> With commandline mvn clean install:

-> Enable tests by commandline mvn clean install -Dmaven.test.skip=false or mvn clean install -DskipTests=false:

SpringBoot Maven Skip Test - run tests

By grokonez | August 26, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *