Hi,
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface DataSet {
public String dataSetLocation() default "";
}
Below is the listener code snippet
@Listeners
public class DataSetListener implements IInvokedMethodListener2, ITestListener{
String xmlData = null;
public void afterInvocation(IInvokedMethod arg0, ITestResult arg1,
ITestContext arg2) {
// TODO Auto-generated method stub
}
public void beforeInvocation(IInvokedMethod method, ITestResult result,
ITestContext context) {
if (method.isTestMethod() && annotationPresent(method, DataSet.class)) {
System.out.println(xmlData);
}
}
public void onStart(ITestContext context) {
ITestNGMethod[] allTestMethods = context.getAllTestMethods();
for (ITestNGMethod iTestNGMethod : context.getAllTestMethods()) {
xmlData = iTestNGMethod.getConstructorOrMethod().getMethod().getAnnotation(DataSet.class).dataSetLocation();
}
}
}
Now when i execute a @Test method with above annotation, nothing happens. The execution doesn't even go to the above listener. Below is the code snippet of Test method.
Note: Both Custom Annotation, Listener and Test Class are in different package in the same project
@DataSet(dataSetLocation = "New Location")
@Test
public void testDataSetAnnotation() {
System.out.println("printed location in listener");
}
Can anyone please help me with how to link a custom annotation to its corresponding listener.