O'Reilly logo

Mastering Microservices with Java by Sourabh Sharma

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing

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

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
</dependency>

To test the RestaurantController, the following files have been added:

  • RestaurantControllerIntegrationTests, 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 String RESTAURANT = "1"; protected ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required