opportunato
opportunato

Reputation: 447

How does Spring Boot Test keep the context across multiple test suites?

I was reading through the guide for using Spring Boot Test and there was a paragraph that got me confused.

“As our profiles get richer, it's tempting to swap every now and then in our integration tests. There are convenient tools to do so, like @ActiveProfiles. However, every time we pull a test with a new profile, a new ApplicationContext gets created.” https://www.baeldung.com/spring-tests

So it assumes that if all tests are run under the same profile, there is only one ApplicationContext created — but how is it possible? I thought that all the objects are recreated for each test suite anyway. Am I missing something?

The official reference says that it's cached.

https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/testing.html#testing-ctx-management

But how does it get loaded into the JUnit runner or Spock one across multiple test suites?

Upvotes: 3

Views: 893

Answers (1)

opportunato
opportunato

Reputation: 447

What was missing in my understanding is the fact that all the test suites are run as a part of a single program, so it's easy to cache any objects that are required by all of them, including Spring context.

Upvotes: 3

Related Questions