Spring Applications

Exercise: Todo REST Testing

  1. Add the Spring starter spring-boot-starter-webmvc-test to the todo REST service.
  2. Add the SQL file data.sql that inserts some test data into the H2 database and set the application property spring.jpa.defer-datasource-initialization to true.
  3. Use the RestTestClient to implement the following tests:
    • TodoControllerMockTest tests only the REST controller, uses a mock environment and mocks the repository
    • TodoControllerMockIT tests the whole REST service using a mock environment
    • TodoControllerIT tests the whole REST service using a running server

Solution