Creating tests using an in-memory database
In the previous recipe, we explored how to get our databases set up with the desired tables and populated with the required data. When it comes to testing, one of the typical challenges is to get the environment set up correctly and predictably so that when the tests are executed, we can safely assert the behavior in a deterministic fashion. In an application that connects to a database, making sure that the database contains a deterministic dataset on which the assertions can be evaluated is extremely important. For an elaborate test suite, it is also necessary to be able to refresh or change that dataset based on the tests. Thankfully, Spring has some nice facilities that aid you in accomplishing this task.
We will pick up from the state of our BookPub
application as we left it in the previous recipe. At this point, we have the schema.sql
file defining all the tables, and we also need the database with some starting data that is defined in data...