title: How to apply play-evolutions when running tests in play-framework?
body: <p>I have problems with evolutions when running tests in play framework using</p>
  
  <ul>
  <li>playframework v2.6.6 for scala</li>
  <li>play-slick v3.0.2</li>
  <li>play-slick-evolutions v3.0.2</li>
  </ul>
  
  <p>The test looks like this:</p>
  
  <pre><code>class TestFooController extends PlaySpec with GuiceOneServerPerSuite {
    "foo endpoint should store some data" in {
      val wsClient = app.injector.instanceOf[WSClient]
      val url = s"http://localhost:$port/foo"
      val requestData = Json.obj("foo" -&gt; "bar")
      val response = await(wsClient.url(url).post(requestData))
      response.status mustBe OK
    }
  }
  </code></pre>
  
  <p>The database configuration looks like this:</p>
  
  <pre><code>slick.dbs.default.driver="slick.driver.H2Driver$"
  slick.dbs.default.db.driver="org.h2.Driver"
  slick.dbs.default.db.url="jdbc:h2:mem:play"
  </code></pre>
  
  <p>Asume there is an evolution script which creates the table <code>foos</code> and this script is working fine in dev mode.</p>
  
  <p>When running the test the following error is thrown:</p>
  
  <p><code>play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[JdbcSQLException: Table "foos" not found;</code></p>
  
  <p>The table <code>foos</code> could not be found so I assume that database evolutions have not been applied.</p>
  
  <p>Then I changed the database configuration to postgresql which is used in dev mode.</p>
  
  <pre><code>slick.dbs.default.driver = "slick.driver.PostgresDriver$"
  slick.dbs.default.db.driver = "org.postgresql.Driver"
  slick.dbs.default.db.url = "jdbc:postgresql://localhost:5432/foo-test"
  slick.dbs.default.db.user = "user"
  slick.dbs.default.db.password = "password"
  </code></pre>
  
  <p>With this configuration the test work fine and data are stored in the database, so database evolutions ran just fine. </p>
  
  <p>Now the problem is, that the database is not cleaned up after tests. I'd like to run each test suite with a clean database.</p>
  
  <p>To sum up. With H2Db evolutions are not applied, with postgresql evolutions are applied but not cleaned up.</p>
  
  <p>Even if this explicitly defined in <code>application.test.conf</code></p>
  
  <pre><code>play.evolutions.autoApply=true
  play.evolutions.autoApplyDowns=true
  </code></pre>
  
  <p>I also tried</p>
  
  <pre><code>play.evolutions.db.default.autoApply=true
  play.evolutions.db.default.autoApplyDowns=true
  </code></pre>
  
  <p>no effect.</p>
  
  <p>Then I tried to do this manually via:</p>
  
  <pre><code>  def withManagedDatabase[T](block: Database =&gt; T): Unit = {
      val dbapi    = app.injector.instanceOf[DBApi]
      val database = dbapi.database("default")
      Evolutions.applyEvolutions(database)
      block(database)
      Evolutions.cleanupEvolutions(database)
    }
  </code></pre>
  
  <p>and then changing the test to:</p>
  
  <pre><code>  "foo endpoint should store some data" in withManagedDatabase { _ =&gt;
      ...
    }
  </code></pre>
  
  <p>For the H2 database configuration it has no effect, the same error that table <code>foos</code> can not be found is thrown. For the postgresql database configuration an evolution exceptions is thrown</p>
  
  <p><code>play.api.db.evolutions.InconsistentDatabase: Database 'default' is in an inconsistent state![An evolution has not been applied properly. Please check the problem and resolve it manually before marking it as resolved.]</code></p>
  
  <p>I want evolution ups running before and evolution downs running after each test suite. How can this be achieved?</p>