我有一个JUnit 3.x TestCase,我希望能够对其进行参数化。我想参数化整个TestCase
(包括灯具)。但是,TestSuite.addTestSuite()
方法不允许传递TestCase
对象,而只能传递一个类:
TestSuite suite = new TestSuite("suite");
suite.addTestSuite(MyTestCase.class);
我希望能够将参数(字符串)传递给在测试运行时创建的MyTestCase实例。现在,我必须为每个参数值使用一个单独的类。
我尝试将其传递给任意子类:
MyTestCase testCase = new MyTestCase() {
String getOption() {
return "some value";
}
}
suite.addTestSuite(testCase.getClass());
但是,这失败并带有以下断言:
... MyTestSuite$1 has no public constructor TestCase(String name) or TestCase()`
有任何想法吗?我是否以错误的方式来解决问题?
最佳答案
如果是Java 5或更高版本,则可能要考虑切换到JUnit 4,该JUnit 4支持内置的参数化测试用例。