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 configures the tests to roll back updates to the SQL database to minimize the risk of negative side effects on other tests...