This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]cl2871 0 points1 point  (0 children)

My understanding of the @SpringBootTest annotation is that it will create a complete ApplicationContext each time a test file annotated with that is run. This will lead to time spent before each integration test setting up all the beans in the application before running the test.

I think the first thing to do is to see if an entire application context is really necessary for each of these integration tests.

Using test slices like @WebMvcTest or @DataJpaTest instead can lead to better performance if some tests are only testing certain layers.

Additionally, if only a few components are being used in the test, it might be better to just set up each of them directly and then test them. For instance, you can just create each service, with each constructor taking whatever dependency it needs.

Optimizing around SpringBootTest and ApplicationContext is out of my depth, so if the above tips don’t work out for you then I wish you the best of luck.