0

I am using Playframework 2.4.6 (want to update to the new version 2.5.0) with Play-Slick.

I have problems to change my unit and integrationtests. When I want to test my controller, I need the database in default status for each test. That means evolution should run for each test.

In my tests I am using h2 InMemory Database.

I tried to set in my testApplication.conf the values:

play.evolutions.autoApply=true
play.evolutions.autoApplyDowns=true
evolutionplugin=enabled
applyEvolutions.default=true
applyDownEvolutions.default=true

with no success.

I am using the OneAppPerTest trait, because I hoped, this trait will reset the database for each test case. No Success.

This is my setup for my test cases:

class MyControllerTest extends FunSuite with OneAppPerTest with OptionValues with MockitoSugar { 

  implicit override def newAppForTest(td: TestData) = new GuiceApplicationBuilder()
    .configure(Map("ehcacheplugin" -> "disabled", "applyDownEvolutions.default" -> "true"))
    .build()
}

For each test I take the controller from Guice:

test("test 1") {
    val controller = app.injector.instanceOf[MyController]
    controller.changeDB // Change
}

When I call my methods on the controller, it will change the database. This change is still there in my second test case.

Help, please.

gun
  • 1,046
  • 11
  • 22

1 Answers1

0

Ok, it works with:

  1. Enhance the Testclass with BeforeAndAfterEach trait

  2. write a method:

override def afterEach() {
  lazy val databaseApi = app.injector.instanceOf[DBApi]
  val db = databaseApi.database("default")
  Evolutions.cleanupEvolutions(
}
gun
  • 1,046
  • 11
  • 22