Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play specs with configuration break because "There is no started application"

I externalized some strings to HOCON, on application.conf. I'm accessing the configuration values like this:

import play.api.Play.current
import play.api.Play.configuration

configuration.getString("foo.bar").get()

As early as possible, to fail fast in case of a missing key, like the docs say.

Now some of my tests that depend on configured objects are failing with a stacktrace that states:

Caused by: java.lang.RuntimeException: There is no started application

I assume this has to do with the configuration? How can I fix this? (tests are specs2)

like image 979
Pablo Fernandez Avatar asked Jun 01 '12 15:06

Pablo Fernandez


1 Answers

Do you have a FakeApplication running? As stated in the documents: http://www.playframework.com/documentation/2.0/JavaTest before you run the test/ test method?

Example from the Wiki:

@Test
public void findById() {
   running(fakeApplication(), new Runnable() {
      public void run() {
        Computer macintosh = Computer.find.byId(21l);
        assertThat(macintosh.name).isEqualTo("Macintosh");
        assertThat(formatted(macintosh.introduced)).isEqualTo("1984-01-24");
       }
   });
}

If this is not solving your issue, perhaps providing more information from the Stacktrace would help.

EDIT: Please tag your question carefully, it does not make sense to mention playframework AND playframework-2.0

like image 107
adis Avatar answered Sep 28 '22 06:09

adis