play2 does not resolve messages when run from a unit test

a 夏天 提交于 2020-01-02 06:42:16

问题


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

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?

Thanks for the help in advance.


回答1:


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


来源:https://stackoverflow.com/questions/17949437/play2-does-not-resolve-messages-when-run-from-a-unit-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!