TestNG 测试重用
需要一些帮助思考 TestNG 术语。我有一个用 TestNG 编写的大型第三方测试套件,我希望能够从中编写测试并从 Intellij 或 Maven 运行它们
是否可以以编程方式组合测试并仍然利用这些其他框架中内置的运行程序。在 JUnit 中你可以这样做:
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ExampleTest extends TestCase {
public static Test suite() {
final TestSuite suite = new TestSuite("suite");
suite.addTestSuite(org.thirdparty.tests.FooTest.class);
suite.addTestSuite(org.thirdparty.tests.BarTest.class);
suite.addTestSuite(org.thirdparty.tests.BazTest.class);
return suite;
}
}
似乎找不到等效的 TestNG 概念。我看到有一个 XmlSuite 类允许以编程方式创建套件,但我认为没有办法将其交给像 Maven Surefire 或 Intellij 这样的测试运行程序。
是否可以简单直接地创建一个测试来移交 XmlSuite 对象或以其他方式以编程方式编写测试,而无需控制测试运行程序?
Need some help thinking in TestNG terms. I have a large third party test suite written in TestNG and I'd like to be able to compose tests from it and run them from Intellij or Maven
Is it possible to compose tests together programmatically and still leverage the runners built into these other frameworks. In JUnit you could do this:
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class ExampleTest extends TestCase {
public static Test suite() {
final TestSuite suite = new TestSuite("suite");
suite.addTestSuite(org.thirdparty.tests.FooTest.class);
suite.addTestSuite(org.thirdparty.tests.BarTest.class);
suite.addTestSuite(org.thirdparty.tests.BazTest.class);
return suite;
}
}
Can't seem to find an equivalent TestNG concept. I see there's an XmlSuite class that allows a suite to be programmatically created, but I see no way to hand this off to a test runner like Maven Surefire or Intellij.
Is it possible to do the simple and direct and create a Test which hands over the XmlSuite object or otherwise programmatically compose tests without also having to control the test runner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有点做作,但您始终可以创建一个 XmlSuite 对象,将 toXml() 的输出保存到文件中,并使用 Surefire 标记来引用该文件。
这能回答你的问题吗?
It's a bit contrived, but you could always create an XmlSuite object, save the output of toXml() to a file and use the tag of Surefire to reference that file.
Does this answer your question?