I am very new to Spring Boot and trying to learn how testing should be done in Spring Boot. I read about the @SpringBootTest annotation which helps in integration testing an application. I was wondering how unit testing should be done in spring boot. Does unit testing require specifying the @SpringBootTest annotation or is that to be used only for integration testing? Are there specific annotations to be used for unit testing?
Any pointers would be much appreciated. Thanks in advance!
Edit: Is the SpringBootTest annotation used only for integration testing? I found the following code example in the Spring documentation:
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class HelloControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void getHello() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
}
}
Is this a unit or integration test? My guess is its not an integration test since it uses a MockMvc. Is that right? If so, does this mean that the @SpringBootTest annotation can be used for tests which are not full fledged integration tests?
newto create your component under test. - JB Nizet