How to reliable identify Failure caused by @BeforeClass?

"Chris [email protected] [junit]" <[email protected]> Mon, 15 Dec 2014 12:11:26 +0000
Newsgroups gmane.comp.java.junit.user
Message-ID <[email protected]>
Hi,

I ran into some issue with a custom runner that I'm maintining and I can do an ugly workaround to fix it, but I'd like to solve it the "right way".

My issue is how to I know if a org.junit.runner.notification.Failure is caused by a normal testcase or if it caused by a crash in a @BeforeClass-annotated method.
The javadoc for Failure says this:

 * A <code>Failure</code> holds a description of the failed test and the
 * exception that was thrown while running it. In most cases the {@link org.junit.runner.Description}
 * will be of a single test. However, if problems are encountered while constructing the
 * test (for example, if a {@link org.junit.BeforeClass} method is not static), it may describe
 * something other than a single test.

But I can't figure out *how* I can read this failure and know that it is BeforeClass or not. I did some really ugly hacks by looking at the backtrace to see where it was triggered from that that's really fragile and I'd like something better.
I tried reading through Description and see if I could figure it out, but no luck thus far.

TIA,
  Chris


------------------------------------
Posted by: Chris <[email protected]>
------------------------------------