Domanda

I'm working on a playframework project, and we test using scalatest. We also want to do some database tests. In conf/application.conf we set up a database connection, but this seems to be ignored when we launch our tests. How can we configure this?

È stato utile?

Soluzione

Your tests needs to be run within the FakeApplication context. You could wrap every test like this (using FunSpec):

describe("MyEntity") {
  it("should do something") {
    running(FakeApplication()) {
      MyEntity.findById(1L).value.name should be("some name")
    }
  }
}

If you don't want to repeat this for every test you can use several methods, see scalatest docs for info about how to share fixures: sharing fixtures

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top