在运行时跳过TestNg测试

tto*_*kic 3 java testng

我没有很多使用TestNG的经验,所以你知道在Java Runtime中跳过或忽略一些测试是热门吗?我的想法是编写@ Before-annotiation测试,如果失败,将忽略传入的测试.

我尝试使用JUnit和assume方法,但我不喜欢它,因为如果"before-test"失败,传入的测试会突出显示为已通过,并且它不是一个可靠的解决方案,因为它具有模糊的含义.

如果您对TestNG有任何经验,请帮助我将不胜感激.

小智 7

您可以通过抛出SkipException跳过测试

throw new SkipException("Skip this");
Run Code Online (Sandbox Code Playgroud)


Ily*_*lya 1

你需要一组测试。注释@Test与下一个参数
dependOnGroup
dependOnMethods

例如

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

@Test(dependsOnMethods={"verifyConfig"})
public void dotest(){
//Actual test
}
Run Code Online (Sandbox Code Playgroud)