【发布时间】:2011-11-07 04:38:39
【问题描述】:
我对 Java 和 JUnit 测试比较陌生。
我非常清楚 Test 类的 ui 是什么,但 TestSuite 类让我感到困惑。
谁能解释一下TestSuite 是干什么用的?
【问题讨论】:
标签: java junit test-suite
我对 Java 和 JUnit 测试比较陌生。
我非常清楚 Test 类的 ui 是什么,但 TestSuite 类让我感到困惑。
谁能解释一下TestSuite 是干什么用的?
【问题讨论】:
标签: java junit test-suite
它是一组测试。它允许您将这样的集合作为一个组运行。
示例来自我在 google 中找到的第一个链接。
import junit.framework.Test;
import junit.framework.TestSuite;
public class EcommerceTestSuite {
public static Test suite() {
TestSuite suite = new TestSuite();
//
// The ShoppingCartTest we created above.
//
suite.addTestSuite(ShoppingCartTest.class);
//
// Another example test suite of tests.
//
suite.addTest(CreditCardTestSuite.suite());
//
// Add more tests here
//
return suite;
}
/**
* Runs the test suite using the textual runner.
*/
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
}
【讨论】:
它基本上是您(或某人)定义一次的一组测试,您只需单击一个按钮即可运行这些测试。测试会自动运行并“标记”,如果任何测试失败,您会被告知详细信息。
【讨论】:
【讨论】: