1
我需要在運行時獲取有關方法偵聽器中方法調用的信息。準確地說,通過數據提供者傳遞給方法的參數的值。Testng:在偵聽器中獲取調用的方法參數信息
這裏是我的測試類
@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);
}
在eclipse調試器中,當我看到IInvokedMethod參數時,我可以看到傳遞參數在對m_parameters 因此,傳遞的「方法」實例包含它在某處..問題是我如何訪問它。 – SK176H
可能的重複http://stackoverflow.com/questions/10538996/testng-testlistener-how-to-reach-testmethod-parameter-in-testlistener-beforein?rq=1 –