In the previous recipes, we have learned how to use Mapper to map database tables into Scala classes and how to use those classes to communicate with the database.
However, there is a small problem; how to test our application without messing with the database. In other words how can we use a database that provides a controlled environment for tests.
The answer to this is an in-memory database that we can reset every time before running the tests.
We will use the project from the previous section. You can duplicate it or use the same project. You will first need to carry out the following steps:
Add the following line in
librariesDependenciesSeq
in thebuild.sbt
file:"com.h2database" % "h2" % "1.3.167" % "test"
Add the following line at the end of the
build.sbt
file:parallelExecution in Test := false
Create a file named
test.default.props
inprops
undersrc/test/resources/
with the following content:db.driver=org...