2

I need to add a custom attribute to existing @Test annotation like below.

@Test (description = "some description", newAttribute = "some value") 
public void testMethod() {
    // unit/integration test code
}

Where 'newAttribute' is the new attribute I have added to existing attributes of @Test. Later as part of reporting, I will read/scrap all files in the workspace for this new attribute and enumerate the tests/methods that use it.

Can it be done in Java? Any help/pointers will be appreciated. Any better way of getting all the tests that use a particular attribute/annotation?

User_77609
  • 33
  • 1
  • 6

1 Answers1

1

No, there is no such thing as annotation inheritance and therefore, you cannot transparently add a value to a compatible type without recompiling the library that defines the annotation. You can however add another annotation to the method:

@Test (description = "some description") 
@NewAttribute ("some value")
public void testMethod() {
    // unit/integration test code
}

You can then read this custom annotation at a later point.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192
  • So I will just add a new Java annotation. And I'm referring http://www.mkyong.com/java/java-custom-annotations-example/ as a starting point. – User_77609 Oct 09 '14 at 14:44