You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Alexander Klimetschek <ak...@day.com> on 2008/02/25 20:14:15 UTC
Logging in Tests
Hi,
I am wondering how to do proper logging in jackrabbit test cases. At
first I used System.out.println() during test case debugging, but now
I want to improve that and switch to "log" (o.a.j.test.LogPrintWriter)
provided by the test base class o.a.j.test.JUnitTest.
Problem is, I cannot get it to print out on the console, neither when
running in Eclipse nor when running with mvn test. I tried it with
providing a log4j.properties file and by specifying the log4j
properties via -D on the mvn command line, but nothing worked.
As there are some test classes using log (eg. ConcurrencyTest), I want
to ask how to make them visible? Nice would be a simple switch that
works both in Eclipse and on the cli with mvn test.
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Logging in Tests
Posted by Marcel Reutegger <ma...@gmx.net>.
Jukka Zitting wrote:
> I don't really understand why the TCK code needs the LogPrintWriter
> construct, but I guess it's there as a bridge for older code or a
> pre-SLF4J attempt to avoid a fixed dependency to a specific logging
> framework. Perhaps we should just refactor LogPrintWriter away.
it's the first. when building the TCK we did not know if it was OK to ship the
TCK without SUNs JavaTest harness. Therefore we created two versions of the TCK
one that solely relied on JUnit with our own webapp based test harness and a
second one that used JavaTest. To be able to pipe log messages into JavaTest we
created the LogPrintWriter.
I guess we don't really need it anymore and it can be removed.
regards
marcel
btw. I find it very useful to have this facility. specifically in integration
tests where assertions become more complex. A JUnit error or fail message
sometimes just isn't helpful enough.
Re: Logging in Tests
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Tue, Feb 26, 2008 at 12:02 AM, Alexander Klimetschek
<ak...@day.com> wrote:
> Am 25.02.2008 um 21:02 schrieb Jukka Zitting:
> > What's the reason for logging in test cases?
>
> Why do other test cases in Jackrabbit use the logging? Why is there a
> logger in the JUnitTest base class?
The logger is mostly used for setup and teardown code.
> The test case is somewhat more complex as it starts an external
> application. This setup can fail and logging helps in seeing the
> problem.
OK, I can understand the need for complexity in setup code, though
IMHO that's still a sign of trouble. If it's something people
generally set up in client applications, you should a utility class or
something (with it's own logging) for doing that. If it's not
something people do, then the test case probably isn't needed.
Anyway, for such cases I'd just use SLF4J logging as we do everywhere else.
I don't really understand why the TCK code needs the LogPrintWriter
construct, but I guess it's there as a bridge for older code or a
pre-SLF4J attempt to avoid a fixed dependency to a specific logging
framework. Perhaps we should just refactor LogPrintWriter away.
BR,
Jukka Zitting
Re: Logging in Tests
Posted by Alexander Klimetschek <ak...@day.com>.
Am 25.02.2008 um 21:02 schrieb Jukka Zitting:
> What's the reason for logging in test cases?
Why do other test cases in Jackrabbit use the logging? Why is there a
logger in the JUnitTest base class?
> If you're writing a
> complex test case where you need logging to follow the control flow,
> then you're probably doing something wrong. In fact a test case rarely
> should have much control flow... A sequence of operations either works
> or doesn't.
The test case is somewhat more complex as it starts an external
application. This setup can fail and logging helps in seeing the
problem.
Otherwise the logging was helpful for developing the test cases - and
I try to practise in all my code to keep the logging messages I wrote
for myself because they document the code and simplify maintaining it
later. I am just in the step of cleaning up the log code so that it
does not fill up normal mvn test commands. The other (IMHO worse)
solution would be to throw it all away.
Regards,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Logging in Tests
Posted by Jukka Zitting <ju...@gmail.com>.
Hi,
On Mon, Feb 25, 2008 at 9:14 PM, Alexander Klimetschek <ak...@day.com> wrote:
> I am wondering how to do proper logging in jackrabbit test cases.
What's the reason for logging in test cases? If you're writing a
complex test case where you need logging to follow the control flow,
then you're probably doing something wrong. In fact a test case rarely
should have much control flow... A sequence of operations either works
or doesn't.
BR,
Jukka Zitting
Re: Logging in Tests
Posted by Alexander Klimetschek <ak...@day.com>.
Am 26.02.2008 um 09:52 schrieb Marcel Reutegger:
> there's an existing log4j.properties file that you can edit in
> jackrabbit-core/src/test/resources/log4j.properties
>
> log4j.logger.org.apache.jackrabbit.test=DEBUG, stdout
Argh, I tried that, but in the wrong location. In the 1.3 branch the
home directory for a test is applications/test, hence I needed to
modify the log4j.properties file there.
I was confused because I was also using Eclipse to run the test and I
thought the location had to be src/test/resources there. But the
project created by mvn eclipse:eclipse puts also applications/test in
the java build path, so log4j finds its property file there as well.
Great, now it works in both mvn and Eclipse.
Thanks,
Alex
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Logging in Tests
Posted by Marcel Reutegger <ma...@gmx.net>.
Alexander Klimetschek wrote:
> I am wondering how to do proper logging in jackrabbit test cases. At
> first I used System.out.println() during test case debugging, but now I
> want to improve that and switch to "log" (o.a.j.test.LogPrintWriter)
> provided by the test base class o.a.j.test.JUnitTest.
>
> Problem is, I cannot get it to print out on the console, neither when
> running in Eclipse nor when running with mvn test. I tried it with
> providing a log4j.properties file and by specifying the log4j properties
> via -D on the mvn command line, but nothing worked.
there's an existing log4j.properties file that you can edit in
jackrabbit-core/src/test/resources/log4j.properties
you just have to change the following line:
log4j.logger.org.apache.jackrabbit.test=DEBUG
to:
log4j.logger.org.apache.jackrabbit.test=DEBUG, stdout
regards
marcel