You want to use @DataJpaTest annotation whenever writing an Integration Test for JPA related components of your application like Entities or Repositories.
@Mock annotation comes from Mockito Framework which allows for easy Mock creation. This annotation is used by MockitoJUnitRunner, each field annotated with it will have Mock for specified class created. This annotation does not inject mocks into tested class on itself, to use injection you need to have target class annotated with @InjectMocks annotation.
You should use @WebMvcTest annotation when you want to write Integration Test that is focused on web layer of your application. @WebMvcTest approach will create ApplicationContext that contains only web components and omits any other components that are not part of web layer. Other components, if required for the test, can be mocked with usage of @MockBean annotation or delivered by @Configuration annotated class imported with usage of @Import annotation.
Integration Test by definition, should check interactions between few components of the system (at least two real, not-mocked components) to check if those components are delivering expected functionalities when working together. In each case when writing Integration Test you should decide how many components should interact in the test for it to be meaningful. Usually, you should decide on smallest possible amount of components that are enough to test specific functionality. Components that are not meaningful can be omitted, or mocked with usage of @MockBean annotation.
spring-boot-starter-test brings following dependencies:
@SpringBootTest annotation will auto-configure:
You should use @SpringBootTest annotation whenever writing JUnit Integration Test for product that is using Spring Boot.
It is a good idea to use external monitoring system, because this way you can use monitoring functionalities without having to spend time coding them.
Spring Actuator allows you to change Health Indicator Status severity order with usage of property management.health.status.order for example:
Spring Actuator provides following Health Indicator Statuses out of the box: