Testing

To enable testing, add the following dependency in the pom.xml file:

<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, which uses the @SpringApplicationConfiguration annotation to pick the same configuration that Spring Boot uses:
@RunWith(SpringJUnit4ClassRunner.class) 
@SpringApplicationConfiguration(classes = RestaurantApp.class) 
public class RestaurantControllerIntegrationTests extends 
        AbstractRestaurantControllerTests { 
 
}
  • An abstract class to write our tests:
public abstract class AbstractRestaurantControllerTests { protected static final ...

Get Mastering Microservices with Java 9 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.