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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.