玩配置规格休息,因为“没有启动的应用程序”(Play specs with configuratio

2019-09-17 16:33发布

我外向一些字符串HOCON,在application.conf 。 我访问这样的配置值:

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

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

尽早,快速失败在缺少键的情况下,如文档说。

现在,我的一些测试依赖于配置的对象与该规定堆栈跟踪失败:

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

我认为这与配置呢? 我怎样才能解决这个问题? (测试是specs2 )

Answer 1:

你有一个FakeApplication运行? 正如文件中规定: http://www.playframework.com/documentation/2.0/JavaTest运行测试/测试方法之前?

从维基例如:

@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");
       }
   });
}

如果不解决您的问题,或许提供从堆栈跟踪信息将帮助。

编辑:请仔细标记您的问题,它没有任何意义说playframeworkplayframework-2.0



文章来源: Play specs with configuration break because “There is no started application”