播放具有配置中断的规范,因为“没有开始的应用程序” [英] Play specs with configuration break because "There is no started application"

查看:179
本文介绍了播放具有配置中断的规范,因为“没有开始的应用程序”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

现在我的一些测试依赖

现在我的一些测试依赖

>配置的
对象失败的堆栈跟踪说明:



原因:java.lang.RuntimeException:没有启动的应用程序



我假设这与配置有关?如何解决这个问题? (测试 specs2

解决方案

您是否有 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 21b);
assertThat(macintosh.name).isEqualTo(Macintosh);
assertThat(formatted(macintosh.introduced))。isEqualTo(1984-01-24);
}
});
}

如果这不是解决你的问题,也许从Stacktrace提供更多的信息帮助。



编辑:请仔细标记您的问题,没有必要提及 playframework AND playframework-2.0


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)

解决方案

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

这篇关于播放具有配置中断的规范,因为“没有开始的应用程序”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆