0

I'm trying to retrieve list of annotation in method level. And created below annotation interface.

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ ElementType.METHOD }) 
    public @interface DataPublish 
    {
       String testName() default "";

    }

Used the annotation in below method:

public class TestCase1 {

    @DataPublish(testName = "This is test name")
    public static void test1() throws Exception {
     try {
         Assert.assertTrue(true);
         } catch (Exception ex) {
            ex.printStackTrace();
        }
      }
 }

I want to get the Field of method level annotation, and wanna change it at runtime. Also, I'm using testNG annotation to execute the code not main method.

ArrchanaMohan
  • 2,314
  • 4
  • 36
  • 84
  • That solution works fine If I kept the annotation in class level but If I kept it in method level throws Null Pointer exception as below FAILED CONFIGURATION: @AfterMethod getRun java.lang.NullPointerException at com.online.pfizer.testreport.publish.TestReuse.getUpdate(TestReuse.java:12) at com.online.pfizer.testreport.publish.TestCase1.getRun(TestCase1.java:28) – ArrchanaMohan Nov 16 '17 at 04:07
  • 1
    same util class has been updated for same usecase here https://github.com/XDean/Java-EX/blob/812198ddbfaefcc370aa7c1480d59ce5beed27b1/src/main/java/xdean/jex/util/reflect/AnnotationUtil.java – Optional Nov 16 '17 at 06:52

0 Answers0