从单元测试运行时play2不能解析消息 [英] play2 does not resolve messages when run from a unit test

查看:90
本文介绍了从单元测试运行时play2不能解析消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为基于Play 2的应用程序运行单元测试,并且在消息方面存在一些问题.显然,这一行似乎无法正确初始化或根本没有初始化.

I'm trying to run unit tests for the Play 2 based application, and we are having some issue regarding the Messages. Apparently, this one seams to not properly initialize or not initialized at all.

@Test
public void testMessage() throws IOException
{
    running(fakeApplication(), new Runnable()
    {
        @Override
        public void run()
        {
            Locale.setDefault(new Locale("en"));
            String test = Messages.get("test.test");
            System.out.println("DUMMY --" + test);
        }
    });
}

上面的代码的输出是:"DUMMY-test.test",尽管我希望得到解决的消息.

The output of the above code is: "DUMMY -- test.test", although I expect the resolved message.

关于该消息是否存在问题?我们是否必须独立加载插件/消息?

Is there an issue regarding the message? Do we have to load the plugin/messages independently?

非常感谢您的帮助.

推荐答案

我不确定是否对您有帮助,但是对于我的代码库,我需要明确地将conf目录添加到我的类路径中以进行测试从该目录访问资源.在我的Build.scala文件中,我有:

I'm not sure if it will help in your case, but for my codebase I needed to explicitly add the conf directory to my classpath to allow tests to access resources from this directory. In my Build.scala file I have:

.settings(
  unmanagedClasspath in Compile <+= baseDirectory map { bd => Attributed.blank(bd / "conf") }
)

这篇关于从单元测试运行时play2不能解析消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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