Sundar
Sundar

Reputation: 387

Play framework 2.1 tests fails to identify started application

I have written few Junit tests and when I try to execute, some tests fail when the DBConnection is initialized with the following error

[error] Caused by: java.lang.RuntimeException: There is no started application
[error]     at scala.sys.package$.error(package.scala:27)
[error]     at play.api.Play$$anonfun$current$1.apply(Play.scala:46)
[error]     at play.api.Play$$anonfun$current$1.apply(Play.scala:46)
[error]     at scala.Option.getOrElse(Option.scala:120)
[error]     at play.api.Play$.current(Play.scala:46)
[error]     at play.api.Play.current(Play.scala)
[error]     at play.Play.application(Play.java:12)
[error]     at DAO.DBManager.<init>(DBManager.java:35)

On a funny note, these tests gets executed in build machine and other machines successfully. This should be some env settings problem. OS : Ubuntu12, Play version : 2.1.0.

Can you guide me what must be wrong?

Update:

There are some tests which use fakeapplication() and some do not. This is causing the problem. If I add fakeapplication() to all the tests or remove it from all the tests then it is passing.

Upvotes: 1

Views: 2663

Answers (1)

Sundar
Sundar

Reputation: 387

I have identified that the problem occurs when we mix the plain junit test and the tests that run with fakeapplication(). When I move all the test run with fakeapplication()or move it to plain junit tests without any of the play's fake application, the tests run without issue. But in windows machine the tests pass irrespective of the mix, that added to the confusion.

Note: You won't be able to run the test that connects to DB with plain junit tests.

Upvotes: 1

Related Questions