Hi guys, I've few questions about unit and integration tests with Spring framework.
Lets suppose I've a simple architecture, made by controllers, services and repositories and I want to use Spring to make some tests with the specific mocks and annotations.
This is what I suppose to use for each layer:
Testing repositories -> @DataJpaTest (H2 in-mem database)
Testing services -> @Mock and @InjectMocks (Mockito library)
Testing controllers -> @WebMvcTest and @MockBean (@MockBean for mocking services)
As you can se I didn't find out a reason to use @SpringBootTest and bootstrap the entire Spring Context.
So, my questions are:
- What's the purpose of the annotation @SpringBootTest and when I should use it bootstrapping the entire application context?
- What if I need to test a specific component that's not a service/controller/repository? Should I use @SpringBootTest just for the specific class(es) I need to test and avoiding to bootstrap the entire context? (IE to test a mapping component)
- How can I perform an end to end test without mocking any component (so a real integration test)? Is it usually required as unit testing single layers?
Thanks for your help.
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me: