有没有办法告诉 Surefire 跳过某个包中的测试?

发布于 2024-10-06 08:30:25 字数 182 浏览 6 评论 0原文

像下面这样的东西。

我想要一种方法来跳过 Surefire 中的 dao 测试。尽量避免定义套件的开销。

对于 CI,我希望每晚运行所有测试,并另外进行 5 分钟的 SCM 轮询,仅运行“快速”测试。

mvn -DskipPattern=**.dao.** test

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情话墙 2024-10-13 08:30:25

让我扩展肖恩的答案。这就是您在 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>

然后在 CI 中像这样启动它们:

mvn -Pfast test

就是这样。

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.

一笔一画续写前缘 2024-10-13 08:30:25

当然,没问题:

<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>

参考:

(排除可以不能通过命令行进行配置,因此如果您想有条件地打开此行为,您必须定义一个配置文件并在命令行上激活它)

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:

(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)

万水千山粽是情ミ 2024-10-13 08:30:25

可以使用命令行排除测试;使用 ! 进行排除。

注意:我不确定,但可能需要 2.19.1 或更高版本的 Surefire 才能工作。

示例:

这不会运行 TestHCatLoaderEncryption

mvn install '-Dtest=!TestHCatLoaderEncryption'

排除包:

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

这也可以与正向过滤器结合使用。以下将运行 0 个测试:

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

请参阅 Maven Surefire 文档< /a>.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文