Share an object reference between various JUnit tests

I have several JUnit tests that need a link for an expensive resource ( WALA hierarchy class ) that takes about 30 seconds to create. I would like to share this link throughout the test suite.

I was thinking of a static member in a base class that is initialized with a method @BeforeClass. After running the test, the JVM should be determined anyway.

Is there any other way to do this? Or any other best practice?

+4
source share
1 answer

Create a clear set of tests (see. This answer ) to run these tests and the use @BeforeClassand @AfterClassin the package (see. The answer ):

@RunWith(Suite.class)
@Suite.SuiteClasses({Test1.class, Test2.class})
public class MySuite {
    @BeforeClass
    public static void initResource() {
        MyExpensiveResource.init();
    }

    @AfterClass
    public static void disposeResource() {
        MyExpensiveResource.dispose();
    }
}
+3
source

Source: https://habr.com/ru/post/1539289/


All Articles