Skip TestNg test in runtime

2019-04-14 23:14发布

问题:

I don't have a lot of experiences with TestNG, so do you know hot to skip or ignore some tests in Java Runtime. My idea is to write @Before-annotiation test and if it fails the incoming test will be ignored.

I tried to use JUnit with assume method, but I don't prefer it because if "before-test" fails the incoming test is highlighted as passed and it's not a reliable solution because it has ambiguous meaning.

So if you have any experiences with TestNG, please help I would be grateful.

回答1:

You need group of tests. Annotation @Test with next params
dependOnGroup or
dependsOnMethods

e.g.

@Test
public void verifyConfig() {
//verify some test config parameters
}

@Test(dependsOnMethods={"verifyConfig"})
public void dotest(){
//Actual test
}


回答2:

You can skip test by throwing SkipException

throw new SkipException("Skip this");


标签: java testng