まさにこの動作を持ち、レポートで認識のためにスキップされたテストとしてそれらを持っていることで私が見つけた最良の方法は、独自のランナーを使用することです(AlexRの回答のように)が、テストを選択できるようにするrunChildメソッドをオーバーライドしますが、無視し、完全に除外しません。
使用するアノテーション
@Retention(RetentionPolicy.RUNTIME)
public @interface TargetOS {
String family();
String name() default "";
String arch() default "";
String version() default "";
}
JUnit ランナー
public class OSSensitiveRunner extends BlockJUnit4ClassRunner {
public OSSensitiveRunner(Class<?> klass) throws InitializationError {
super(klass);
}
@Override
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
Description description = describeChild(method);
if (method.getAnnotation(Ignore.class) != null) {
notifier.fireTestIgnored(description);
} else if (method.getAnnotation(TargetOS.class) != null) {
final TargetOS tos = method.getAnnotation(TargetOS.class);
String name = tos.name().equals("") ? null : tos.name();
String arch = tos.arch().equals("") ? null : tos.arch();
String version = tos.version().equals("") ? null : tos.version();
if (OS.isOs(tos.family(), name, arch, version)) {
runLeaf(methodBlock(method), description, notifier);
} else {
notifier.fireTestIgnored(description);
}
} else {
runLeaf(methodBlock(method), description, notifier);
}
}
}
テストでの使用
@RunWith(OSSensitiveRunner.class)
public class SeleniumDownloadHelperTest {
...
特定のメソッドを制限する
@Test
@TargetOS(family = "windows")
public void testGetFileFromUrlInternetExplorer() throws Exception {
...
}