我收到以下代码的“java.lang.Exception:方法tearDown 应该没有参数”并且 result.getStatus 为 null
我有 JUnit 来运行案例
package com;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
public class DeleteLeter {
@Test
public void testw() throws Exception{
WebDriver driver = new FirefoxDriver();
driver.get("http://e4allapac");
int a =10;
int b=20;
Assert.assertEquals(a, b);
}
@After
public void tearDown(ITestResult result){
System.out.println(result.getStatus());
if(ITestResult.FAILURE==result.getStatus())
System.out.println("Fail");
}
}
最佳答案
听起来您想实现 TestWatcher
规则 - http://junit.org/junit4/javadoc/4.12/index.html .
基本思想是,您创建一个扩展 TestWatcher 类的类,将其作为 @Rule
附加到您的测试套件,然后在测试失败时它将收到通知。
public class MyWatcher extends TestWatcher {
@Override
protected void failed(Throwable e, Description description) {
// do whatever Selenium magic here.
}
}
public class MyTests {
@Rule
public final MyWatcher myWatcher = new MyWatcher();
@Test
public void testMethod() {
// test stuff goes in here
}
}
关于java - 我收到以下代码的 "java.lang.Exception: Method tearDown should have no parameters"& result.getStatus 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41695179/