Testing your logging (best practices)

Discussion in 'Java' started by Hoss Spence, Feb 7, 2008.

  1. Hoss Spence

    Hoss Spence Guest

    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.
     
    Hoss Spence, Feb 7, 2008
    #1
    1. Advertisements

  2. 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.
     
    Roger Lindsjö, Feb 9, 2008
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.