Logging in to test modules 2.3

Unable to get any registration result in unit tests in Play 2.3 using Logger.error("an error") . I tried all these examples that seem to be out of date.

The closest I got with build.sbt containing the following:

 testOptions in Test += Tests.Argument("-Dlogger.resource=conf/test-logger.xml") 

This causes the test-logger.xml configure the logger, but I still don't get any results.

Has anyone had success with this in Play 2.3?

Workaround Workaround

I am currently using the quick-use class to handle this until it is fixed. Added here as it may be useful for someone else.

 public class Logger { public static void debug(String message) { System.out.println(String.format("[debug] %s", message)); } public static void info(String message) { System.out.println(String.format("[info] %s", message)); } public static void warn(String message) { System.out.println(String.format("[warn] %s", message)); } public static void error(String message) { System.err.println(String.format("[error] %s", message)); } } 
+6
source share
3 answers

@Jamesinchina updated his answer (in the question I referred to) to support Play Framework 2.3 :

I edited the answer to remove play.Project, which was deleted in 2.3.x, but the rest are still working - we are currently using it in our project.

Adding the conf/test-logger.xml and the following line to build.sbt does the trick:

 javaOptions in Test += "-Dlogger.file=conf/test-logger.xml" 

Updated Answer

+7
source

Since Play 2.5 everything is configured only through logback, so we can rely on the default login mechanisms to find the configs: http://logback.qos.ch/manual/configuration.html .

This means that inside the <project_or_module>/test/resources folder, you can put a file called logback-test.xml , which takes precedence over the standard logback.xml , since both are on the class path when performing tests.

+3
source

You can try adding this to your build.sbt file:

testOptions + = Tests. Argument (TestFrameworks.JUnit, "-v", "-q")

Check out this page: https://groups.google.com/forum/#!topic/play-framework/WiqpjWZ_Qt0

+1
source

Source: https://habr.com/ru/post/973484/


All Articles