Andrew Golovko
@andrewgolovko
Blog of a self-taught programmer writing about the experience, tips and other stuff
153 posts

M04 Q44 When do you want use @DataJpaTest for? What does it auto-configure?

You want to use @DataJpaTest annotation whenever writing an Integration Test for JPA related components of your application like Entities or Repositories.

M04 Q43 What are the differences between @MockBean and @Mock?

@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.

M04 Q42 When do you want to use @WebMvcTest? What does it auto-configure?

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.

M04 Q41 How do you perform integration testing with @SpringBootTest for a web application?

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.

M04 Q40 What dependencies does spring-boot-starter-test brings to the classpath?

spring-boot-starter-test brings following dependencies:

M04 Q39 What does @SpringBootTest auto-configure?

@SpringBootTest annotation will auto-configure:

M04 Q38 When do you want to use @SpringBootTest annotation?

You should use @SpringBootTest annotation whenever writing JUnit Integration Test for product that is using Spring Boot.

M04 Q37 Why do you want to leverage 3rd-party external monitoring system?

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.

M04 Q36 How do you change the Health Indicator status severity order?

Spring Actuator allows you to change Health Indicator Status severity order with usage of property management.health.status.order for example:

M04 Q35 What are the Health Indicator statuses that are provided out of the box?

Spring Actuator provides following Health Indicator Statuses out of the box: