Get name of currently executing test in JUnit 4

Posted by Dave Ray on Stack Overflow See other posts from Stack Overflow or by Dave Ray
Published on 2009-01-23T15:51:14Z Indexed on 2010/03/26 18:53 UTC
Read the original article Hit count: 363

Filed under:
|
|

In JUnit 3, I could get the name of the currently running test like this:

public class MyTest extends TestCase
{
    public void testSomething()
    {
        System.out.println("Current test is " + getName());
        ...
    }
}

which would print "Current test is testSomething".

Is there any out-of-the-box or simple way to do this in JUnit 4?

Background: Obviously, I don't want to just print the name of the test. I want to load test-specific data that is stored in a resource with the same name as the test. You know, convention over configuration and all that.

Thanks!

© Stack Overflow or respective owner

Related posts about junit

Related posts about java