我在运行时遇到问题,ITestListener给我以下错误:
侦听器类ListenerTest必须是ITestListener,ISuiteListener,IReporter,IAnnotationTransformer,IMethodInterceptor或IInvokedMethodListener之一
但是,我已经实现了ITestListener。当我通过testng.xml执行时,此方法工作正常,但当尝试通过Java程序(RunTestNG.java)执行时,此方法效果不佳。我看到过其他引用此问题的帖子,那里的解决方案似乎无法解决我的问题。关于如何解决此问题的任何想法?
import org.testng.TestNG;
public class RunTestNG {
public static void main(String[] args) {
RunTestNG rt = new RunTestNG();
rt.testNGSuite();
}
public void testNGSuite() {
RunTestNG tla = new RunTestNG();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { LoginTest.class });
testng.addListener(ListenerTest.class);
testng.run();
}
}
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
public class ListenerTest implements ITestListener{
public void onTestStart(ITestResult result) {
// TODO Auto-generated method stub
}
public void onTestSuccess(ITestResult result) {
// TODO Auto-generated method stub
}
public void onTestFailure(ITestResult result) {
// TODO Auto-generated method stub
}
public void onTestSkipped(ITestResult result) {
// TODO Auto-generated method stub
}
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
// TODO Auto-generated method stub
}
public void onStart(ITestContext context) {
// TODO Auto-generated method stub
}
public void onFinish(ITestContext context) {
// TODO Auto-generated method stub
}
}