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.
1 Answer
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.