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

南楼画角 提交于 2019-11-26 09:50:13

问题


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

回答1:


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.




回答2:


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)




回答3:


It is possible to exclude tests using the commandline; using ! to exclude.

Note: I'm not sure but possibly needs 2.19.1 or later version of surefire to work.

Examples:

This will not run TestHCatLoaderEncryption

mvn install '-Dtest=!TestHCatLoaderEncryption'

Exclude a package:

mvn install '-Dtest=!org.apache.hadoop.**'

This can be combined with positive filters as well. The following will run 0 tests:

mvn install '-Dtest=Test*CatLoaderEncryption,!TestHCatLoaderEncryption'

See the Maven Surefire docs.



来源:https://stackoverflow.com/questions/4389744/is-there-a-way-to-tell-surefire-to-skip-tests-in-a-certain-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!