3

I'm trying to create a custom rule in JUnit which only runs on test methods that I have a custom annotation on. The thing is I can't see a way to find out if the method wrapped in the Statement instance has the annotation set. I was thinking I could use reflection but how could I tell if the method in the Statement represents one of the annotated methods? Not really sure how to approach this. Thanks.

André Gasser
  • 1,065
  • 2
  • 14
  • 34
AlyoshaKaramazov
  • 616
  • 1
  • 9
  • 25

1 Answers1

2

You can simply use the instance of the Description class passed into the Statement. See the javadoc for Description#getAnnotation().

For more information, please see my answer to Mark unit test as an expected failure in JUnit.

Community
  • 1
  • 1
Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171