title: Play 2.1 Unit Test With Slick and Postgres
body: <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>