The @BeforeAll
annotation marks a method to run before all tests in a class.
http://junit.org/junit5/docs/current/user-guide/#writing-tests-ann
You can mark each of your test classes that uses your database with an interface that defines a static
BeforeAll
(so that it cannot be overridden). e.g.:
interface UsesDatabase {
@BeforeAll
static void initializeDatabaseConnections() {
// initialize database connections
}
}
This method will be invoked once for each implementing class so you will need to define a way to initialize your connections only once and then do nothing for the other calls.