Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip TestNg test in runtime

Tags:

java

testng

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.

like image 555
ttokic Avatar asked Dec 27 '22 04:12

ttokic


2 Answers

You can skip test by throwing SkipException

throw new SkipException("Skip this");
like image 73
Rohit Avatar answered Jan 30 '23 18:01

Rohit


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
}
like image 32
Ilya Avatar answered Jan 30 '23 16:01

Ilya