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
Contents
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:
Then modify SpringMavenSkipTestApplicationTests class as below:
package com.javasampleapproach.maven.skiptest; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest public class SpringMavenSkipTestApplicationTests { @Test public void contextLoads() { System.out.println("###############################################################"); System.out.println("============================Testing============================"); System.out.println("###############################################################"); } }
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.
– skipTests
is the feature of Surefire. It will complile BUT NOT run the tests.
2.2 skipping by default
We set properties {skipTests
, maven.test.skip
} in the pom.xml file.
with maven.test.skip
[...] ... [...]true ...
To enable test, we use commandline: mvn clean install -Dmaven.test.skip=false
.
with skipTests
[...] ... [...]true ...[...] org.apache.maven.plugins maven-surefire-plugin ${skipTests}
To enable test, we use commandline: mvn clean install -DskipTests=false
.
results
-> With commandline mvn clean install
:
-> Enable tests by commandline mvn clean install -Dmaven.test.skip=false
or mvn clean install -DskipTests=false
: