1

需要一些帮助以 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 对象或以其他方式以编程方式编写测试,而不必控制测试运行器?

4

1 回答 1

2

这有点做作,但您总是可以创建一个 XmlSuite 对象,将 toXml() 的输出保存到一个文件并使用 Surefire 的标签来引用该文件。

这回答了你的问题了吗?

于 2010-08-29T04:40:06.847 回答