testNg でこれを行う方法の 1 つは、 IAnnotationTransformer リスナーを使用することです。基本的に、実行時に注釈を操作できます。以下に例を示します。
リスナー:
public class SampleAnnotationTransformer implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation iTestAnnotation, Class aClass, Constructor constructor, Method method) {
if(method != null){
if(!isThisTestCompatible(method)){
//diable the test case.
iTestAnnotation.setEnabled(false);
}
}
}
private boolean isThisTestCompatible(Method method){
//your logic goes here...
return false;
}
}
以下に示すように、testNG で上記のリスナーを構成します。
<suite name="Suit" verbose="1">
<listeners>
<listener class-name="SampleAnnotationTransformer" />
</listeners>
//test cases...
http://testng.org/doc/documentation-main.html#testng-listenersで他のリスナーもチェックする価値があります