Spring IInvokedMethodListener期望所有配置和测试方法都在实现类上
我正在使用TestNG的Spring IInvokedMethodListener期望所有配置和测试方法都在实现类上,spring,testng,Spring,Testng,我正在使用TestNG的IInvokedMethodListener在执行测试方法后执行某些操作- public class MyListener implements IInvokedMethodListener { @Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { Method testMethod = getClass().getMethod(result.
IInvokedMethodListener
在执行测试方法后执行某些操作-
public class MyListener implements IInvokedMethodListener {
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
Method testMethod = getClass().getMethod(result.getName());
}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
// some magic here
}
但是使用mvn test
执行测试会导致以下错误-
java.lang.NoSuchMethodException:com.savingglobal.opsys.webui.util.MyListener.springTestContextPrepareTestInstance
java.lang.NoSuchMethodException:com.savingglobal.opsys.webui.util.MyListener.springTestContextBeforeTestMethod()
以及所有的配置方法和我的测试方法。我是不是用错了听者?我正在测试6.9.10注意:getClass()
将返回MyListener.class
和result.getName()
可能返回方法的名称
但是如果您想要执行方法
,只需使用Method.getTestMethod().getConstructorMethod().getMethod()
注意:getClass()
将返回MyListener.class
和result.getName()
可能返回方法的名称
但是如果您想要执行
方法
,只需使用方法.getTestMethod().getConstructorMethod().getMethod()
,您没有提供足够的上下文。可以共享更多代码和完整的堆栈跟踪吗?你如何注册你的听众?您可以尝试在没有maven的情况下运行测试吗?错误来自第行methodtestmethod=getClass()。getMethod(result.getName())
更新了问题。因为MyListener没有springTestContextBeforeTestClass配置,所以我得到了这个错误。但我如何获得testMethod的引用呢?当我不使用maven并以TestNG test的形式运行测试方法时,会出现错误。我不理解您试图执行的操作:getClass()
将返回MyListener.class
和result。getName()
可能返回方法的名称。但是如果您想要执行的方法,只需使用Method.getTestMethod().getConstructorMethod().getMethod().getMethod()
awesome效果很好,请将其作为答案发布,我接受您没有提供足够的上下文。可以共享更多代码和完整的堆栈跟踪吗?你如何注册你的听众?您可以尝试在没有maven的情况下运行测试吗?错误来自第行methodtestmethod=getClass()。getMethod(result.getName())
更新了问题。因为MyListener没有springTestContextBeforeTestClass配置,所以我得到了这个错误。但我如何获得testMethod的引用呢?当我不使用maven并以TestNG test的形式运行测试方法时,会出现错误。我不理解您试图执行的操作:getClass()
将返回MyListener.class
和result。getName()
可能返回方法的名称。但是如果您想要执行的方法,只需使用Method.getTestMethod().getConstructorMethod().getMethod().getMethod()
awesome效果很好,请将其作为答案发布,我会接受它