Testng : 获取监听器中调用的方法参数信息

Testng : Get invoked method parameter information in a listener

我需要在运行时在方法侦听器中获取有关方法调用的信息。准确地说是通过数据提供程序传递给方法的参数值。

这是我的测试Class

@Listeners(MyListener.class)
class MyTest{

   @Test(dataProvider="myDataProvider")
   public void myTest(ITestContext context , SomeParam param){
      // test something
   }    
}

这是我的听众

public class MyListener implements IInvokedMethodListener2{
  // other methods omitted

 @Override
 public void beforeInvocation(IInvokedMethod method, 
           ITestResult testResult,  ITestContext context) {

    // so i have access to the invoked method thru the "method"
    // argument.
    // I need to print the value of SomeParam that was 
    // passed to the method  
    // what do i do here to get access to the 
    // instance of SomeParam that was passed to the method ?

    SomeParam param = method.what().to().call();
    System.out.println(param);

}

参数存储在 testResult 中而不是方法中,因此 testResult.getParameters() 工作正常。