在运行时跳过TestNg测试

5
我对TestNG的经验不是很丰富,您知道如何在Java Runtime中跳过或忽略某些测试吗?我的想法是编写@Before注释测试,如果它失败,则会忽略后续测试。
我尝试使用JUnit的假设方法,但我不喜欢它,因为如果“before-test”失败,则后续测试将被标记为已通过,这不是可靠的解决方案,因为其含义模糊。
因此,如果您有任何TestNG的经验,请帮助一下,我将非常感激。
2个回答

9
您可以通过抛出SkipException来跳过测试。
throw new SkipException("Skip this");

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

例如:

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接