Run database once per Spek suite

203 views Asked by At

Some tests require running a database, for instance, using Test Containers Library. It obviously takes time to boot it up.

Is there a way to do this only once per entire Spek suite which spans across multiple files? The docs don't say anything about this.

Anyone knows why this has not been implemented?

1

There are 1 answers

0
Richard North On

This answer is not Spek-specific, but Testcontainers objects expose a simple start() and stop() method, meaning that you don't have to rely on the test framework to control your container lifecycle if you don't want to. You can create a container in a static object that is separate from your test classes, and then access it across all tests if you like.

Please see an example here (Java example snippet below):

static {
    GenericContainer redis = new GenericContainer("redis:3-alpine")
            .withExposedPorts(6379);
    redis.start();
}

I would imagine an equivalent in Kotlin should be quite easy as an object (or similar).