![](/img/trans.png)
[英]How to use datadriven test within @BeforeClass method in TestNG framework
[英]TestNG How to execute beforeclass() method on testfailure
我在beforeclass()
中有登录步骤,之后测试开始执行。 如果测试失败,则应该重新调用beforeclass()
方法。 我正在使用测试监听器 class。
public class LoginTests {
@BeforeClass
public void beforeClass() throws Exception {
System.out.print("login in application");
}
@BeforeMethod
public void beforeMethod() {
}
@AfterClass
public void afterClass(){
}
@Test
public void test1() {
System.out.print("go to first page");
}
@Test
public void test2() {
System.out.print("go to second page");
}
public void onTestFailure(ITestResult result) {
//if there is test failure run beforeclass() method
}
}
@AfterMethod
可以知道测试的结果,如果失败了,可以重复 after 方法中的逻辑。 在这种情况下不需要测试监听器。
@BeforeClass
public void beforeClass() throws Exception {
//login
}
@AfterMethod
public void afterMethod(ITestContext tc, ITestResult result) {
if (result.isSuccess()) {
return;
}
// login
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.