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(en
Throwing a SkipException in a method annotated with @BeforeMethod did not work for me because it skipped all the remaining tests of my test suite with no regards if a SkipException were thrown for those tests.
I did not investigate it thoroughly but I found another way : using the dependsOnMethods attribute on the @Test annotation:
import org.testng.SkipException;
import org.testng.annotations.Test;
public class MyTest {
private boolean conditionX = true;
private boolean conditionY = false;
@Test
public void isConditionX(){
if(!conditionX){
throw new SkipException("skipped because of X is false");
}
}
@Test
public void isConditionY(){
if(!conditionY){
throw new SkipException("skipped because of Y is false");
}
}
@Test(dependsOnMethods="isConditionX")
public void test1(){
}
@Test(dependsOnMethods="isConditionY")
public void test2(){
}
}