通过配置中断播放规范,因为"没有启动的应用程序"

Pab*_*dez 11 configuration specs2 playframework-2.0

我将一些字符串外部化为HOCON application.conf.我正在访问这样的配置值:

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

configuration.getString("foo.bar").get()
Run Code Online (Sandbox Code Playgroud)

尽可能早,如果缺少密钥就会快速失败,就像文档说的那样.

现在我的一些依赖于配置对象的测试失败了,堆栈跟踪表明:

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

我假设这与配置有关?我怎样才能解决这个问题?(测试是规格2)

adi*_*dis 9

你有FakeApplication跑步吗?正如文档中所述:http://www.playframework.com/documentation/2.0/JavaTest在运行测试/测试方法之前?

来自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");
       }
   });
}
Run Code Online (Sandbox Code Playgroud)

如果这不能解决您的问题,也许从Stacktrace提供更多信息会有所帮助.

编辑:请仔细标记您的问题,提及playframeworkAND 没有意义playframework-2.0

  • 那么,我需要**包含在该块中的每一个测试**只是为了使用一些配置值?必须有一个更容易/非黑客的方式 (4认同)