Ankit Kumar
Ankit Kumar

Reputation: 1463

How does JUnit process the @Before annotation

I was looking at Java's Reflection feature and got to know about the proxy pattern used for the purpose to write annotation processors. Is there a similar @Before class annotation processor written inside org.junit package? I tried finding it but couldn't locate the exact class which does this job.

Upvotes: 1

Views: 477

Answers (1)

Michael Aaron Safyan
Michael Aaron Safyan

Reputation: 95499

It depends on what you mean. The term "annotation processor" often refers to a plugin that runs during the compilation phase to generate code based on annotations. In this case, however, the @Before, @After, and @Test annotations can be trivially processed at runtime simply by invoking Class.getMethods() to retrieve the list of methods on the test class, and then using Method.getAnnotation() or Method.getDeclaredAnnotations() to inspect the annotations on the methods of that class to find the methods with those annotations.

Upvotes: 3

Related Questions