Junit 4, how to disable creating new instance of Test per test method

java, junit4, testing

Solution

For the sake of making this an answer:

public class MyTestClass {
    private static String onceForAllTests;

    @AfterClass
    public static void afterClass() {
        onceForAllTests = null; // silly, but just to demonstrate
    }

    @BeforeClass
    public static void beforeClass() {
        onceForAllTests = "This is set once for all tests";
    }

    @Test
    public void sillyTest {
        String someTestValue = "This is set during method";
        assertNotEquals( onceForAllTests, someTestValue );
    }
}

Problem

Is there some way to disable creation new instance of Test per @Test ?

Original source