Writing automated tests that focus on persistence

When writing persistence tests, we want to start an embedded database when the tests begin and tear it down when the tests complete. However, we don't want the tests to wait for other resources to start up, for example, a web server such as Netty (which is required in runtime).

Spring Boot comes with two class level annotations tailored for this specific requirement: 

  • @DataMongoTest: This starts up an embedded MongoDB database when the test starts.
  • @DataJpaTest: This starts up an embedded SQL database when the test starts:
    • Since we added a test dependency in the build file for the review microservice to the H2 database, it will be used as the embedded SQL database.
    • By default, Spring Boot ...

Get Hands-On Microservices with Spring Boot and Spring Cloud 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.