如何让 TestNG 在特定组中运行测试(从命令行)?

发布于 2024-09-14 19:12:09 字数 551 浏览 0 评论 0原文

我从命令行调用 TestNG,如下所示:

java org.testng.TestNG -groups "foo" testng.xml

...目的是仅运行带有以下注释的测试:

@Test(groups = { "foo" })

...但它正在运行我的所有测试。我需要更改 testng.xml 文件吗?

<suite name="BarSuite" verbose="1">
  <test name="AllInPackage">
    <packages>
      <package name="com.example.bar"/>
   </packages>
 </test>
</suite>

TestNG 是否忽略 -groups 命令行参数,因为 testng.xml 表示运行包中的所有测试?如果是这样,我应该如何更改我的 testng.xml 文件?

I'm invoking TestNG from the command-line like this:

java org.testng.TestNG -groups "foo" testng.xml

...with the intention of only running tests annotated with:

@Test(groups = { "foo" })

...but it's running all my tests. Do I need to change my testng.xml file?

<suite name="BarSuite" verbose="1">
  <test name="AllInPackage">
    <packages>
      <package name="com.example.bar"/>
   </packages>
 </test>
</suite>

Is TestNG ignoring the -groups command-line argument because testng.xml says to run all the tests in the package? If so, how should I change my testng.xml file?

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

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

发布评论

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

评论(2

余生共白头 2024-09-21 19:12:09

你说得完全正确:如果你指定一个 testng.xml,它优先于命令行开关。

只需将以下内容添加到您的 XML 文件中:

  <groups>
    <run>
      <include name="foo"  />
    </run>
  </groups>

You got it exactly right: if you specify a testng.xml, it takes precedence over the command line switches.

Just add the following to your XML file:

  <groups>
    <run>
      <include name="foo"  />
    </run>
  </groups>
婴鹅 2024-09-21 19:12:09

Java:
在特定组中使用 TestNG 运行测试非常简单:
1)在命令行中打开项目文件夹
示例:cd C:\FunctionalTests
2) 按组 group1、group2 运行测试

mvn test -Dgroups=group1,group2

- 测试组的名称
Java 中的示例

注意!
如果您的项目构建管理器是 maven,则 mvn test 命令有效。
如果您不知道您正在使用哪种构建管理器,您可以通过检查(即)项目中的 pom.xml 是否存在来验证它

Java:
Running tests with TestNG in specific groups is very easy:
1) Open you project folder in command line
example: cd C:\FunctionalTests
2) Run test by group

mvn test -Dgroups=group1,group2

group1, group2 - name of the test group
example in java

NB!
mvn test command works, if your project building manager is maven.
If you dont know, what kind of building manager you are using, you can verify it by checking (i.e) pom.xml existence in your project

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