TestNG测试重用

时间:2010-08-29 02:57:01

标签: java maven-2 junit intellij-idea 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这样的测试运行器。

是否可以执行简单直接的操作并创建一个Test,它可以移交XmlSuite对象或以其他方式编写测试而无需控制测试运行器?

1 个答案:

答案 0 :(得分:2)

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

这会回答你的问题吗?