mercredi 10 avril 2019

Reuse Spring application context across different Spock tests

I would like to reuse the same Spring context across several integration tests written in Spock framework. According to the documentation context caching is based on classes property of @ContextConfiguration annotation.

That's an example test:

@SpringBootTest
@ContextConfiguration(classes = Application.class)
class ExampleIntegrationTest extends Specification {

    def 'should reuse Spring context if already created'() {
        expect:
        1 == 1
    }
}

The second test also contains the same @ContextConfiguration annotation, i.e.

@ContextConfiguration(classes = Application.class)

but when I run all tests I can see in the console that Spring context is created per each test. I would like to cache it between different tests. Am I missing something? Basically, I would like to achieve the same thing as described here (stackoverflow question) but in Spock instead of JUnit.

Aucun commentaire:

Enregistrer un commentaire