我得到了一个“答案”;java.lang.Exception:方法tearDown应该没有参数;对于以下代码&;result.getStatus为空

我得到了一个“答案”;java.lang.Exception:方法tearDown应该没有参数;对于以下代码&;result.getStatus为空,java,selenium,junit,Java,Selenium,Junit,我得到下面代码的“java.lang.Exception:Method 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.fire

我得到下面代码的“java.lang.Exception:Method 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
规则-

基本思想是创建一个扩展TestWatcher类的类,将其作为
@规则
附加到测试套件中,然后在测试失败时收到通知

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
  }
}

删除
tearDown
方法即可。jUnit将在开箱即用的情况下完成它的工作。我需要获得测试的状态,因此如果测试失败,那么我将添加代码来捕获屏幕快照。啊,我看到您混合了jUnit和testNg。如果我使用@Test(TestNG),那么它将显示缺少的主要方法&如果我add@Test(JUnit)然后我得到“java.lang.Exception:方法tearDown应该没有参数”,请建议一个或另一个;做好一件事。我建议你不要再迷惑自己了太棒了。。。谢谢大家。