piotrek
piotrek

Reputation: 14540

spring-boot: building only part of the context for tests

by default spring-boot does a lot of auto-discovery and registration of components based on classpath. same goes for tests. but let's say i want test my DAOs that uses spring-jpa. so there is no point in loading everything except Db layer (flyway, @Repository, datasource) as it takes much more time to run such tests.

how can i run tests that configure only this part of whole spring context?

Upvotes: 2

Views: 310

Answers (1)

C-Otto
C-Otto

Reputation: 5843

The @DataJpaTest annotation was created exactly for this use case: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4#testing-the-jpa-slice

Upvotes: 2

Related Questions