When we do integration testing, we would want to launch the embedded server with all the controllers and beans that are configured. This code snippet shows how we can create a simple integration test:
@RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class BasicControllerIT { private static final String LOCAL_HOST = "http://localhost:"; @LocalServerPort private int port; private TestRestTemplate template = new TestRestTemplate(); @Test public void welcome() throws Exception { ResponseEntity<String> response = template .getForEntity(createURL("/welcome"), String.class); assertThat(response.getBody(), equalTo("Hello World")); } ...