the use case is simple: I want to run some boiler plate code before each method in the JUnit test annotated with @Test and my custom annotation (let her call @Mine).
I do not want to use the following methods (explanation in parentheses):
- @RunWith (my test may or may not use this annotation already, so I can’t assume that I can use my own runner)
- AOP (I can’t install dependencies on third-party libraries like AspectJ)
I guess that only leaves me with a reflection, and that’s fine. I tried using @Before and getting the current method via Thread.getCurrentThread (), etc., but for some reason I find this solution a bit dirty, since I will have to make the boiler plate code in this method again to reflect (and to avoid unnecessary code was the goal in the first place).
Perhaps you have other ideas?
java reflection junit aop
ŁukaszBachman Nov 22 '11 at 21:12 2011-11-22 21:12
source share