Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring IInvokedMethodListener期望所有配置和测试方法都在实现类上_Spring_Testng - Fatal编程技术网

Spring IInvokedMethodListener期望所有配置和测试方法都在实现类上

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.

我正在使用TestNG的
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效果很好,请将其作为答案发布,我会接受它