如何让 TestNG 在特定组中运行测试(从命令行)?
我从命令行调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你说得完全正确:如果你指定一个 testng.xml,它优先于命令行开关。
只需将以下内容添加到您的 XML 文件中:
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:
Java:
在特定组中使用 TestNG 运行测试非常简单:
1)在命令行中打开项目文件夹
示例:
cd C:\FunctionalTests
2) 按组 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
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