I am trying to start a fake play application to do some integration tests of a users repository. The fake application should have the additional configuration to point to a test database, that will be cleared after the tests. This is my code, that tries to insert a new user into the test database:
class MyTest extends WithApplication {
@Override
def provideApplication(): FakeApplication = {
FakeApplication(
additionalConfiguration = Map(
"db.default.driver" -> "com.mysql.jdbc.Driver",
"db.default.url" -> "jdbc:mysql://localhost/playit_test",
"db.default.user" -> "root",
"db.default.password" -> ""
)
)
}
@Test
def myTest(): Unit = {
val user: User = new User()
user.setName("Test")
UsersRepository.insert(user)
}
}
The fake application should be provided by WithApplication
, but when I run the test I get the following error:
Connected to the target VM, address: '127.0.0.1:57138', transport: 'socket'
[info] - application - Creating Pool for datasource 'default'
[info] - play.api.libs.concurrent.ActorSystemProvider - Starting application default Akka system: application
java.lang.RuntimeException: There is no started application
... Stack trace
Disconnected from the target VM, address: '127.0.0.1:57138', transport: 'socket'
The exception is thrown exactly in this line DB.withConnection { implicit c =>
. It seems this code does not see the running fake application. Am I doing something wrong or is there other way to do it?
Aucun commentaire:
Enregistrer un commentaire