To enable testing, the following dependency in the pom.xml file is used:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> </dependency>
To test the RestaurantController, the following files have been added:
- The RestaurantControllerIntegrationTests class uses the
@SpringBootTest annotation to pick the same configuration that Spring Boot uses. Also, we use the SpringRunner class to run our integration tests. Please find the restaurant API integration test code:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RestaurantApp.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"management.server.port=0", "management.context-path=/admin"})
public class RestaurantControllerIntegrationTests extends
AbstractRestaurantControllerTests...