在运行时跳过TestNg测试

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

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

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

你需要一组测试。 使用下一个参数注释@Test
dependOnGroup或
dependsOnMethods

例如

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

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

 throw new SkipException("Skip this");