Lightbend Activator

Slick TestKit Example (Slick 3.0)

Activator will be EOL-ed on May 24, 2017.

We’re making it easier and simpler for developers to get started with Lightbend technologies. This unfortunately means that future releases of Play, Akka and Scala will no longer include Activator support, and Lightbend’s Activator server will be decommissioned by the end of 2017. Instead of supporting Activator to create and set up development projects, we'll be supporting standard Giter8 templates for sbt users and Maven archetypes for Maven users. So going forward,

To create new Lightbend projects

Instead of using the Activator command, make sure you have sbt 0.13.13 (or higher), and use the “sbt new” command, providing the name of the template. For example, “$ sbt new akka/hello-akka.g8”. You can find a list of templates here.

Also, as a convenience, the Lightbend Project Starter allows you to quickly create a variety of example projects that you just unzip and run.

To create new templates

If you want to create new templates, you can now do that in Giter8.

To migrate templates from Activator to Giter8

If you created Activator templates in the past, please consider migrating them to Giter8 with this simple process.

Slick TestKit Example (Slick 3.0)

March 30, 2015
slick scala

This template shows you how to use Slick's TestKit library to test your own Slick driver.

How to get "Slick TestKit Example (Slick 3.0)" on your computer

There are several ways to get this template.

Option 1: Choose slick-testkit-example-3.0 in the Lightbend Activator UI.

Already have Lightbend Activator (get it here)? Launch the UI then search for slick-testkit-example-3.0 in the list of templates.

Option 2: Download the slick-testkit-example-3.0 project as a zip archive

If you haven't installed Activator, you can get the code by downloading the template bundle for slick-testkit-example-3.0.

  1. Download the Template Bundle for "Slick TestKit Example (Slick 3.0)"
  2. Extract the downloaded zip file to your system
  3. The bundle includes a small bootstrap script that can start Activator. To start Lightbend Activator's UI:

    In your File Explorer, navigate into the directory that the template was extracted to, right-click on the file named "activator.bat", then select "Open", and if prompted with a warning, click to continue:

    Or from a command line:

     C:\Users\typesafe\slick-testkit-example-3.0> activator ui 
    This will start Lightbend Activator and open this template in your browser.

Option 3: Create a slick-testkit-example-3.0 project from the command line

If you have Lightbend Activator, use its command line mode to create a new project from this template. Type activator new PROJECTNAME slick-testkit-example-3.0 on the command line.

Option 4: View the template source

The creator of this template maintains it at

Option 5: Preview the tutorial below

We've included the text of this template's tutorial below, but it may work better if you view it inside Activator on your computer. Activator tutorials are often designed to be interactive.

Preview the tutorial

Slick TestKit

When you write your own database driver 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.

This template contains a copy of Slick's standard PostgreSQL driver and all the infrastructure required to build and test it from its own sbt / Activator project.


The 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 logback-test.xml but you can swap out the logging framework if you prefer a different one.


The actual driver implementation can be found in MyPostgresDriver.scala. It is a copy of Slick's PostgresDriver which has been renamed to MyPostgresDriver.

Test Harness

In order to run the TestKit tests, you need to add a class that extends DriverTest, plus an implementation of TestDB which tells the TestKit how to connect to a test database, get a list of tables, clean up between tests, etc.

In the case of the MyPostgreSQL test harness in MyPostgresTest.scala most of the default implementations can be used out of the box. Only getLocalTables and getLocalSequences require custom implementations. We also modify the driver's capabilities to indicate that our driver does not support the JDBC getFunctions call:

class MyPostgresTest extends DriverTest(MyPostgresTest.tdb)

object MyPostgresTest {
  def tdb = new ExternalJdbcTestDB("mypostgres") {
    val driver = MyPostgresDriver
    override def localTables(implicit ec: ExecutionContext): DBIO[Vector[String]] = ...
    override def getLocalSequences(implicit session: profile.Backend#Session) = ...
    override def capabilities = ...

The name of a configuration prefix, in this case mypostgres, is passed to ExternalJdbcTestDB:

def tdb =
  new ExternalJdbcTestDB("mypostgres") ...

Database Configuration

Since the PostgreSQL test harness is based on ExternalJdbcTestDB, it needs to be configured in testkit.conf. In order to run the tests, you need a PostgreSQL server with an account which allows you to create tablespaces and databases. Enter the user name and password in the configuration (and don't forget to save the file):

mypostgres.enabled = true
mypostgres.user = myuser
mypostgres.password = secret

If you installed PotgreSQL on OSX with Homebrew, this should be your own user name and an empty password. For a standard PostgreSQL installation on Windows, use the credentials you entered in the installer.

There are several other configuration options that need to be set for an ExternalJdbcTestDB. These are defined with suitable defaults in testkit-reference.conf so that testkit.conf can be kept very simple in most cases.

Run the Tests

You can run the tests on the Test page (or with sbt test on the command line). sbt discovers the JUnit test 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 driver (as determined by the capabilities setting in the test harness) to be run.

Note: When running the tests here in Activator (as of version 1.1.3), you will only see a single-line summary of the passed tests in Test and you may not get a proper test report at all when a test fails. You can switch to Compile for the complete log output that shows the individual tests.

Next Steps

Check out the full Slick manual and API docs.

You can also find more Slick templates, contributed by both, the Slick team and the community, here in Activator.