[Hawkular-dev] What should be the replacement for printlns in tests?

Thomas Segismont tsegismo at redhat.com
Wed Jan 27 07:18:02 EST 2016


In Metrics, we use Logback. The Logback JAR is added to the test scope 
and we have a logback-test.xml file in src/test/resources

The nice thing with Logback is that you can include system property 
references in the configuration file. Consequently, it's very easy to 
adapt logging to different use cases:
- tests run during a build on Travis
- tests run during a dev build
- tests started from the IDE
- ... etc

Here's an example conf file:

https://github.com/hawkular/hawkular-metrics/blob/master/core/metrics-core-service/src/test/resources/logback-test.xml

Note that log level defaults to error. And here is how the level is set 
to INFO for Travis builds:

https://github.com/hawkular/hawkular-metrics/blob/master/.travis.yml#L46

As for adding a rule to prevent println, I err on the side of "please 
don't". In the past, we have taken care of this kind of issues during 
code reviews, and it works well.

Le 27/01/2016 10:44, Peter Palaga a écrit :
> Hi *,
>
> Short version: How to configure the log levels for individual
> jboss.logging loggers in tests run by maven outside the container?
>
> Long version:
> I was recently assigned https://issues.jboss.org/browse/HAWKULAR-264 Add
> println checks to the checkstyle. It says that "Tests shouldn't be
> allowed to have printlns, we should enforce this via the checkstyle plugin."
>
> I fully agree for tests being run on the server side - those can use
> JBoss Logging in the very same manner as the server code.
>
> However, what is the best replacement for println()s in tests that are
> run outside the server?
>
> I tried using JBoss Logging there too but I failed completely to find a
> way to configure the log levels for individual loggers. Does anybody
> know how to do that?
>
> To get my work done without using printlns, I started to use
> java.util.logging configured via logging.properties :
> https://github.com/hawkular/hawkular-agent/blob/master/hawkular-wildfly-agent-itest-parent/hawkular-wildfly-agent-itest/src/test/resources/logging.properties
>
> So what should be the replacement for printlns in tests?
>
> Thanks,
>
> Peter
> _______________________________________________
> hawkular-dev mailing list
> hawkular-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hawkular-dev
>



More information about the hawkular-dev mailing list