Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping tests in some modules in Maven

I would like my Maven builds to run most unit tests. But there are unit tests in one project which are slower and I'd like to generally exclude them; and occasionally turn them on.

Question: How do I do this?

I know about -Dmaven.test.skip=true, but that turns off all unit tests.

I also know about skipping integration tests, described here. But I do not have integration tests, just unit tests, and I don't have any explicit calls to the maven-surefire-plugin. (I am using Maven 2 with the Eclipse-Maven plugin).

like image 565
Joshua Fox Avatar asked Apr 21 '09 14:04

Joshua Fox


People also ask

How do I skip a module in Maven build?

Maven version 3.2. 1 added this feature, you can use the -pl switch (shortcut for --projects list) with ! or - (source) to exclude certain submodules. Be careful in bash the character ! is a special character, so you either have to single quote it (like I did) or escape it with the backslash character.

How can I skip test cases in Eclipse?

You can put the property maven. test. skip in a profile in your pom. And then you activate this profile in eclipse in the project properties of maven in eclipse.


2 Answers

What about skipping tests only in this module ?

In the pom.xml of this module:

<project>   [...]   <build>     <plugins>       <plugin>         <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-surefire-plugin</artifactId>         <version>2.4.2</version>         <configuration>           <skipTests>true</skipTests>         </configuration>       </plugin>     </plugins>   </build>   [...] </project> 

Eventually, you can create a profile that will disable the tests (still the pom.xml of the module) :

<project>   [...]   <profiles>     <profile>       <id>noTest</id>       <activation>         <property>           <name>noTest</name>           <value>true</value>         </property>       </activation>       <build>         <plugins>           <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-surefire-plugin</artifactId>             <version>2.4.2</version>             <configuration>               <skipTests>true</skipTests>             </configuration>           </plugin>         </plugins>       </build>     </profile>   </profiles>   [...] </project> 

With the latter solution, if you run mvn clean package, it will run all tests. If you run mvn clean package -DnoTest=true, it will not run the tests for this module.

like image 81
Romain Linsolas Avatar answered Oct 14 '22 17:10

Romain Linsolas


I think this is easier, and also has the benefit of working for non-surefire tests (in my case, FlexUnitTests)

<profile>    <id>noTest</id>     <properties>        <maven.test.skip>true</maven.test.skip>     </properties>  </profile> 
like image 34
Luiz Henrique Martins Lins Rol Avatar answered Oct 14 '22 19:10

Luiz Henrique Martins Lins Rol