【发布时间】:2021-05-10 20:50:51
【问题描述】:
MyBaseIntegrationTestCase 是一个类,它是大约 150 个测试类的父类。
现在,我想让MyBaseIntegrationTestCase参数化(参数是外部软件的版本)
所以,我把它改成类似
@RunWith(Parameterized.class)
public abstract class MyBaseIntegrationTestCase extends MyBaseTestCase{
@Parameterized.Parameters(name = "with ExternalSoftware-v{0}")
public static List<String[]> allVersions() {
return Arrays.asList( ...);
}
@Parameterized.Parameter
public String externalSoftwareVersion;
}
MyBaseIntegrationTestCase 的所有子代都已参数化并成功运行,MyTestClass 除外,声明为
@RunWith(Parameterized::class)
class MyTestClass(override var myType: ParameterType) : MyBaseIntegrationTestCase() {
companion object {
@Parameterized.Parameters(name = "with {0}")
@JvmStatic
fun allTypes(): Collection<Array<ParameterType>> = ...
}
失败了
java.lang.Exception: 测试类应该有一个公共的零参数构造函数
我想让 MyBaseIntegrationTestCase 的所有子项按照父类中的定义参数化运行,并使 MyTestClass 在 allType 和 allVersions 的笛卡尔积上参数化
不可能使MyTestClass 不扩展MyBaseIntegrationTestCase,这将需要大量的东西来复制粘贴。
您能建议如何在 JUnit4 中执行此操作吗?
【问题讨论】:
标签: junit junit4 parameterized parameterized-unit-test