重复 JUnit3 测试

发布于 2025-01-03 01:39:24 字数 191 浏览 5 评论 0原文

我正在使用 Apache 的 Surefire JUnit Maven 插件。

我想在 JUnit 3.x 中重新运行测试套件。这在 JUnit 4 中很容易实现,它提供了“参数化”注释。

你知道我如何在 JUnit 3.x 中做同样的事情吗?

我的目标是运行整套测试两次,以便可以将两个不同的测试数据植入到所有测试中。

I am using Apache's Surefire JUnit plug-in for maven.

I would like to re-run a test suite in JUnit 3.x. This is possible easily in JUnit 4, which offers the 'Parameterized' annotation.

Do you know how I can do the same in JUnit 3.x?

My goal is to run the entire suite of tests twice so that two different test data can be seeded into all the tests.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

娇女薄笑 2025-01-10 01:39:24

在 JUnit 3.x 中,您可以定义自己的测试套件。如果您向 JUnit 类添加

public static Test suite() 

方法,JUnit 将运行返回变量中定义的所有方法。您可以查看 JUnit 和 junit.framework.TestSuite - 没有可运行的方法< /a> (针对问题)或 http://junit.org/apidocs/junit/framework/TestSuite.html

你也可以这样做:

public static Test suite() {
    TestSuite suite = new TestSuite(YouTestClass.class);
    suite.addTest(new TestSuite(YouTestClass.class)); //you want to run all twice
    // suite.addTest(new YouTestClass("foo", 0);
    // for (int i = 0; i < TEST_SETALL.length; i++) {
    // suite.addTest(new YouTestClass("setAllTest",i ));
    // }

    Test setup = new TestSetup(suite) {
        protected void setUp() throws Exception {
            // do your one time set-up here!
        }

        protected void tearDown() throws Exception {
            // do your one time tear down here!
        }
    };

    return setup;
}

In JUnit 3.x you can define your own test suite. If you add

public static Test suite() 

method to yout JUnit class than JUnit will run all methods that are defined in the returned variable. You can look on JUnit and junit.framework.TestSuite - No runnable methods (to the question) or http://junit.org/apidocs/junit/framework/TestSuite.html

You can do also something like this:

public static Test suite() {
    TestSuite suite = new TestSuite(YouTestClass.class);
    suite.addTest(new TestSuite(YouTestClass.class)); //you want to run all twice
    // suite.addTest(new YouTestClass("foo", 0);
    // for (int i = 0; i < TEST_SETALL.length; i++) {
    // suite.addTest(new YouTestClass("setAllTest",i ));
    // }

    Test setup = new TestSetup(suite) {
        protected void setUp() throws Exception {
            // do your one time set-up here!
        }

        protected void tearDown() throws Exception {
            // do your one time tear down here!
        }
    };

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