Issue
Is there currently a way to disable TestNG test based on a condition
I know you can currently disable test as so in TestNG:
@Test(enabled=false, group={"blah"})
public void testCurrency(){
...
}
I will like to disable the same test based on a condition but dont know how. something Like this:
@Test(enabled={isUk() ? false : true), group={"blah"})
public void testCurrency(){
...
}
Anyone has a clue on whether this is possible or not.
Solution
You have two options:
- Implement an annotation transformer.
- Use BeanShell.
Your annotation transformer would test the condition and then override the @Test annotation to add the attribute "enabled=false" if the condition is not satisfied.
Answered By - Cedric Beust
Answer Checked By - Cary Denson (JavaFixing Admin)