When you write your own database profile for Slick, you need a way to run all the standard unit tests on it (in addition to any custom tests you may want to add) to ensure that it works correctly and does not claim to support any capabilities which are not actually implemented. For this purpose the Slick unit tests have been factored out into a separate Slick TestKit project.
To get started, you can clone the Slick TestKit Example template which contains a copy of Slick’s standard PostgreSQL profile and all the infrastructure required to build and test it.
build.sbt file is straight-forward. Apart from the usual name and
version settings, it adds the dependencies for Slick, the TestKit,
junit-interface, Logback and the PostgreSQL JDBC driver, and it sets some
options for the test runs:
There is a copy of Slick’s logback configuration in
src/test/resources/logback-test.xml but you can swap out the logging
framework if you prefer a different one.
The actual profile implementation can be found under
In order to run the TestKit tests, you need to add a class that extends
ProfileTest, plus an implementation of
TestDB which tells the TestKit
how to connect to a test database, get a list of tables, clean up between
In the case of the PostgreSQL test harness (in
most of the default implementations can be used out of the box. Only
getLocalSequences require custom implementations. We also modify the profile’s
to indicate that our profile does not support the JDBC
The name of a configuration prefix, in this case
mypostgres, is passed to
Since the PostgreSQL test harness is based on
ExternalJdbcTestDB, it needs to be configured in
There are several other configuration options that need to be set for an
These are defined with suitable defaults in
testkit-reference.conf so that
be kept very simple in most cases.
sbt test discovers
MyPostgresTest and runs it with TestKit’s
JUnit runner. This in turn causes the database to be set up through the test
harness and all tests which are applicable for the profile (as determined by
capabilities setting in the test harness) to be run.