Testing your logging (best practices)

H

Hoss Spence

Curious how many test their logging statements here. To test that my
logging is what I expect it to be I usually create an instance
variable e.g. mLogMessage. I set it and log it, then check my
mLogMessage in my Junit test. This allows me to test what I'd expect
my log to be without checking the log file itself. The negative is
that I have a getLogMessage() which is only used by Junit. Wondered
what other approaches people use.
 
R

Roger Lindsjö

Hoss said:
Curious how many test their logging statements here. To test that my
logging is what I expect it to be I usually create an instance
variable e.g. mLogMessage. I set it and log it, then check my
mLogMessage in my Junit test. This allows me to test what I'd expect
my log to be without checking the log file itself. The negative is
that I have a getLogMessage() which is only used by Junit. Wondered
what other approaches people use.

What logging framework are you using. You could probably create your own
log listener / handler (or whatever they are called in your framework)
which gives you access to logged messages from withing you unit test.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top