我的具体问题是关于JUnit的参数化测试,如果它包含某个属性,则过滤(基本上不运行)测试.例如:
@Test
public void test1() {
if (property.contains("example")) {
return;
}
assertEquals(expected, methodToTest1(actual));
}
@Test
public void test2() {
if (property.contains("example")) {
return;
}
assertEquals(expected, methodToTest2(actual));
}
Run Code Online (Sandbox Code Playgroud)
问题是,是否存在一种技术,其中约束if (property.equals("example"))...
在其他地方静态定义,而不是在每个测试方法之前?像这样:
/** define constraint "property.equals("example")" somewhere **/
@Test
public void test1() {
assertEquals(expected, methodToTest1(actual));
}
@Test
public void test2() {
assertEquals(expected, methodToTest2(actual));
}
Run Code Online (Sandbox Code Playgroud)
您可以使用JUnit的假设功能一起@Before
.
@Before
向测试类添加方法
@Before
public void dontRunIfExample() {
assumeFalse(property.contains("example"));
}
Run Code Online (Sandbox Code Playgroud)
并if
从每个测试中删除块.
归档时间: |
|
查看次数: |
51 次 |
最近记录: |