问题
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