Maven: How to skip a test in some projects via command line options?

In my maven project, I have several modules. Is it possible to disable the start of unit test for some modules using command line options?

My project takes about 15 minutes to complete all unit tests. I would like to speed up the general assembly by doing only unit tests in the module I'm working on. I do not want to enter and edit every single pom.xml to achieve this.

I tried the solution described here: Can I run a specific testng test group through maven? However, the result is a lot of testing errors in the modules that I want to Skip. I believe that a β€œgroup” is not the same concept of a module?

+52
maven maven-2
Feb 03 2018-12-12T00:
source share
3 answers

To enable or disable unit tests for the entire project, use the Maven Surefire Plugin Ability to skip tests . There is a drawback to using skipTests from the command line. In a scenario for building multiple modules, this will disable all tests in all modules.

If you need finer grain control of running a subset of the tests for a module, consider using inclusion and exclusion for testing Maven Surefire Plugin .

To enable command line overrides, use the POM properties when configuring the Surefire plugin. Take, for example, the following POM segment:

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.9</version> <configuration> <excludes> <exclude>${someModule.test.excludes}</exclude> </excludes> <includes> <include>${someModule.test.includes}</include> </includes> </configuration> </plugin> </plugins> </build> <properties> <someModule.skip.tests>false</someModule.skip.tests> <skipTests>${someModule.skip.tests}</skipTests> <someModule.test.includes>**/*Test.java</someModule.test.includes> <someModule.test.excludes>**/*Test.java.bogus</someModule.test.excludes> </properties> 

With POM, as mentioned above, you can perform tests in various ways.

  • Run all the tests (the above configuration includes all the source files ** / * Test.java).
 mvn test 
  1. Skip all tests in all modules
 mvn -DskipTests=true test 
  1. Skip all tests for a specific module
 mvn -DsomeModule.skip.tests=true test 
  1. Run only specific tests for a specific module (this example includes all ** / * IncludeTest.java source files).
 mvn -DsomeModule.test.includes="**/*IncludeTest.java" test 
  1. Exclude specific tests for a specific module (this example excludes all ** ** * * ExcludeTest.java source files)
 mvn -DsomeModule.test.excludes="**/*ExcludeTest.java" test 
+70
Feb 04 2018-12-12T00:
source share

... and if you want to pass the parameter to the maven release plugin in Hudson / Jenkins, you need to use -Darguments=-DskipTests to make it work.

+13
Dec 12 '12 at 15:28
source share

If you want to use Maven profiles:

you can make it work by doing something like this:

  • Skipping tests in some modules in Maven

I don't know if there is a supported command line option that does the same thing.

You can also try to directly use the properties of the environment, something in accordance with this page of the document:

i.e. something like:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> <configuration> <skipTests>${moduleA.skipTests}</skipTests> </configuration> </plugin> 

then using mvn -DmoduleA.skipTests=false test to verify that there is one module.

+4
Feb 03 '12 at 3:10
source share



All Articles