gradle 测试过滤不适用于参数化适配器。例如,
@RunWith(Parameterized.class)
public class FooTest {
@Test
public void testFoo() {
}
}
对参数 1 运行一种测试方法:
gradle test --tests com.example.test.FooTest.testFoo[1]
作品。
但是对于包裹 Parameterized.class 的 runner 适配器,它不起作用。
public class HelloAdapter extends Runner {
private Runner wrapped;
public HelloAdapter(Class testClass) {
this.wrapped = new Parameterized(testClass);
}
@Override
public void run(RunNotifier notifier) {
wrapped.run(notifier);
}
}
@RunWith(HelloAdapter.class)
public class FooTest {
@Test
public void testFoo() {
}
}
为参数 1 运行一种方法:
gradle test --tests com.example.test.FooTest.testFoo[1]
[1] 将被忽略。Gradle 将对所有参数 [0]、[1]、[2]、... 运行测试
HelloAdapter 不能继承 Parameterized,因为它可以是多个运行器的适配器。