Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to tell surefire to skip tests in a certain package?

Something like the following.

I would like a way to skip my dao tests in surefire. Trying to avoid overhead of defining Suites.

With CI I'd like to have one nightly that runs all tests and another 5 minute poll of SCM that runs only 'fast' tests.

mvn -DskipPattern=**.dao.** test 
like image 585
Eric Winter Avatar asked Dec 08 '10 16:12

Eric Winter


People also ask

How do you skip an integration-test?

If, instead, you want to skip only the integration tests being run by the Failsafe Plugin, you would use the skipITs property instead: mvn install -DskipITs.

How do you skip a unit test?

test. skip=true to skip the entire unit test. By default, when building project, Maven will run the entire unit tests automatically.

How can you override skipTests parameter in command line?

Skipping by default by initializing the skipTests element value to true in properties and then overriding it through the command line by mentioning the value of -DskipTests in the maven phase/build execution command.

How do I skip a test in Jenkins build?

We can simply skip or ignore them. This behavior is specified in Jenkins. For a Maven project we simply set a parameter in the JVM options of our Maven configuration. This will disable or skip all of the tests in this project.


2 Answers

Let me extend Sean's answer. This is what you set in pom.xml:

<properties>   <exclude.tests>nothing-to-exclude</exclude.tests> </properties> <profiles>   <profile>     <id>fast</id>     <properties>       <exclude.tests>**/*Dao*.java</exclude.tests>     </properties>   </profile> </profiles> <plugin>   <groupId>org.apache.maven.plugins</groupId>   <artifactId>maven-surefire-plugin</artifactId>   <configuration>     <excludes>      <exclude>${exclude.tests}</exclude>     </excludes>   </configuration> </plugin> 

Then in CI you start them like this:

mvn -Pfast test 

That's it.

like image 50
yegor256 Avatar answered Oct 25 '22 11:10

yegor256


Sure, no problem:

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-surefire-plugin</artifactId>    <version>2.6</version>    <configuration>       <excludes>          <!-- classes that include the name Dao -->          <exclude>**/*Dao*.java</exclude>          <!-- classes in a package whose last segment is named dao -->          <exclude>**/dao/*.java</exclude>       </excludes>    </configuration> </plugin> 

Reference:

  • Maven Surefire Plugin > Inclusions and Exclusions of Tests

(The excludes can not be configured via command line, so if you want to turn this behavior on conditionally, you will have to define a profile and activate that on the command line)

like image 30
Sean Patrick Floyd Avatar answered Oct 25 '22 11:10

Sean Patrick Floyd