carrotsearch/junit-benchmarks — pull request #14 by dscho (2014-03-16 00:54:21+00:00)
Title: Add a workaround for JUNITBENCH-54

Reflection is often not the correct way to do things, but sometimes it
cannot be helped, for example when JUnit does not give us a chance to
measure the time the original test statement without including the
runtime of the methods annotated with @Before and @After.

The problem is that JUnit wraps statements into, say, a RunAfter
statement that ensures that not only the test statement in question is
executed but also the @After-annotated methods. The same is done for
@Before methods, and for a couple of other things, so that eventually
the test statement about which we want to gather statistics is wrapped
into multiple layers of wrapping statements like an onion into its seven
skins.

With this commit, we cheat and access the private fields of RunAfter and
friends, and inject our own BenchmarkStatement (wrapping the statement
we desire to wrap) into the inner-most 'onion skin'.

We also handle the other statements JUnit 4.11 might wrap around our
desired test statement:

https://github.com/junit-team/junit/blob/r4.11/src/main/java/org/junit/runners/BlockJUnit4ClassRunner.java#L251

Signed-off-by: Johannes Schindelin