【问题标题】:Multiple TestNG groups: can they be ANDed exclusively from the command line?多个 TestNG 组:它们可以在命令行中独占吗?
【发布时间】:2015-10-14 22:58:38
【问题描述】:

假设我有一个桌面用户界面和一个移动用户界面,用于相同的后端功能(例如帐户、结帐)。然后我会有以下测试类:

@Test(groups = { "desktop", "account" })
public class DesktopAccountTest {}

@Test(groups = { "desktop", "checkout" })
public class DesktopCheckoutTest {}

@Test(groups = { "mobile", "account" })
public class MobileAccountTest {}

@Test(groups = { "mobile", "checkout" })
public class MobileCheckoutTest {}

我永远不需要同时运行桌面和移动测试。另一方面,我想运行所有桌面测试或所有移动测试,这很容易使用mvn test -Dgroups="desktop"mvn test -Dgroups="mobile"。但是,例如,如果我只想运行桌面帐户测试怎么办?这不起作用:mvn test -Dgroups="desktop, account":它返回所有桌面测试和所有帐户测试。

有没有办法得到两组的交集,而不是它们的总和?从命令行?

【问题讨论】:

    标签: java maven command-line testng


    【解决方案1】:

    你应该试试mvn test -Dgroups="desktop,account"-DexcludedGtoups="mobile"

    但如果你只想运行一个测试,也可以:http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html

    【讨论】:

    • 我尝试了你的建议。它提供了额外的过滤,但仍然基于 2 组的总和,而不是它们的交集。无论如何,你仍然得到我的投票:)
    • 是的,但目前只有 TestNG 支持收件箱。您可以使用IMethodInterceptor 轻松做出自己的选择,您可以在其中过滤您不想要的测试。
    【解决方案2】:

    另一种解决方案是为每个特定组创建一个testng.xml 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 2015-09-29
      相关资源
      最近更新 更多