Note that there are some explanatory texts on larger screens.

plurals
  1. POPlay 2.1 Unit Test With Slick and Postgres
    primarykey
    data
    text
    <p>I want to run unit tests for a Play 2 Scala app using the same database setup as used in production: Slick with Postgres. The following fails with "java.sql.SQLException: Attempting to obtain a connection from a pool that has already been shutdown." on the 2nd test.</p> <pre><code>package controllers import org.specs2.mutable._ import play.api.db.DB import play.api.Play.current import play.api.test._ import play.api.test.Helpers._ import scala.slick.driver.PostgresDriver.simple._ class BogusTest extends Specification { def postgresDatabase(name: String = "default", options: Map[String, String] = Map.empty): Map[String, String] = Map( "db.test.driver" -&gt; "org.postgresql.Driver", "db.test.user" -&gt; "postgres", "db.test.password" -&gt; "blah", "db.test.url" -&gt; "jdbc:postgresql://localhost/blah" ) def fakeApp[T](block: =&gt; T): T = running(FakeApplication(additionalConfiguration = postgresDatabase("test") ++ Map("evolutionplugin" -&gt; "disabled"))) { def database = Database.forDataSource(DB.getDataSource("test")) database.withSession { implicit s: Session =&gt; block } } "Fire 1" should { "do something" in fakeApp { success } } "Fire 2" should { "do something else" in fakeApp { success } } } </code></pre> <p>I run the test like this:</p> <pre><code>$ play -Dconfig.file=`pwd`/conf/dev.conf "test-only controllers.BogusTest" </code></pre> <p>Two other mysteries: </p> <p>1) All tests run, even though I ask for just BogusTest to run</p> <p>2) application.conf is always used, not def.conf, and the driver information comes from application.conf, not the info configured in the code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload