Reputation: 2375
I am currently working on getting the Flexmojos project to build with the new Adobe Flex 4.8. The problem is, that with 4.8 one feature is no longer available. If I run the unittests against this sdk, the build will fail. I could disable the failling tests alltogether, but I would like to keep them in place, as they test important features of older Flex SDKs.
Is there a way to automatically have tests skipped if a precondition is not met? I was thinking of some method being called to decide if a test should be executed. Alternatively I could set an environment variable. If there is any other option I would be glad to hear.
Chris
Upvotes: 1
Views: 982
Reputation: 1035
One way i can think of doing this in testNg is by using IAnnotationTransformer listener. Basically you can manipulate the annotation in runtime. here is an example:
Listener:
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;
}
}
configure above listener in testNG as shown below:
<suite name="Suit" verbose="1">
<listeners>
<listener class-name="SampleAnnotationTransformer" />
</listeners>
//test cases...
Worth checking other listeners as well at http://testng.org/doc/documentation-main.html#testng-listeners
Upvotes: 3