【问题标题】:How to group our test cases in Junit 3如何在 Junit 3 中对我们的测试用例进行分组
【发布时间】:2012-08-17 06:23:23
【问题描述】:

我需要从我的测试套件中运行一些选定的测试用例。测试用例在不同的测试类中可用。是否可以创建一些自定义注释并将 junit 配置为仅运行带有该注释的测试用例?

如果您有任何建议,请告诉我。谢谢

【问题讨论】:

标签: junit


【解决方案1】:

TestSuite 是测试的组合。它运行一组测试用例。这是一个使用动态测试定义的示例。

 TestSuite suite= new TestSuite();
 suite.addTest(new MathTest("testAdd"));
 suite.addTest(new MathTest("testDivideByZero"));

另外,TestSuite 可以提取要自动运行的测试。为此,您将 TestCase 类的类传递给 TestSuite 构造函数。

 TestSuite suite= new TestSuite(MathTest.class);

此构造函数创建一个套件,其中包含所有以“test”开头且不带参数的方法。

最后一个选择是对大量测试类执行相同的操作。

 Class[] testClasses = { MathTest.class, AnotherTest.class }
 TestSuite suite= new TestSuite(testClasses);

来源:http://www.junit.org/apidocs/junit/framework/TestSuite.html

【讨论】:

    猜你喜欢
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 2021-09-21
    • 1970-01-01
    • 2012-05-21
    • 2021-08-02
    • 1970-01-01
    相关资源
    最近更新 更多