TestNG 测试重用

发布于 2024-09-16 02:33:10 字数 798 浏览 5 评论 0原文

需要一些帮助思考 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 技术交流群。

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

发布评论

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

评论(1

很酷不放纵 2024-09-23 02:33:10

这有点做作,但您始终可以创建一个 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?

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