Re: How to reliable identify Failure caused by @BeforeClass?

"David Saff [email protected] [junit]" <[email protected]> Mon, 15 Dec 2014 11:45:30 -0500
Newsgroups gmane.comp.java.junit.user
Message-ID <CALrw-PyzhF9ePtsrceoT_2XxJMOPyDBhBcw4s2OmAbju1kN6xw@mail.gmail.com>
At the moment, I don't think there's machine-readable metadata that would
help identify the source of a failure.  That line in the javadoc is
supposed to simply warn that some Failures thrown won't have Descriptions
attached that refer to tests already in the test tree, if the Failure
reported is in test machinery that doesn't correspond to an individual test.

What is it you're hoping to do?

On Mon, Dec 15, 2014 at 7:11 AM, Chris [email protected] [junit] <
[email protected]> wrote:
>
>
>
> 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
>  
>