Best practices in test logging

Hi!

My test suites are growing rapidly. Sometimes it is really hard to find
meningful test output in long and bloated test.log.

Do you have any advices or best practices when it comes to logging in
tests?

So far I have been using following policy:

  1. Log test name in every test_* method

    I have a method that puts coloured test name in the log. The problem
    is that
    I have to invoke this method manually in each test method. And it
    looks quite
    ugly:

    def test_reject_duplicate_account_name_on_signup
    log_test_name(“test_reject_duplicate_account_name_on_signup”)
    … # Rest of the test goes here

    How to make Test::Unit log test name automatically?

  2. Log failures using logger

    A small replacement function for Test::Unit::Assertions::assert_block
    is
    enough to write ‘Success’ or ‘Failed: …’ in test logs.

  3. Log everything from within tests, nothing from application.

    I try to make application methods as short and clean as possible. And
    that
    means (almost) no logging in the application itself. Only some really
    uncommon/strange/error situations have logging statements.

  4. Use log when necessary, remove when no longer needed

    All the introspection I do when needed in tests. And that means
    removing
    logging statements from tests as soon as they are not needed - when
    test
    passes.

Do you have any thoughts or suggestions to improve my test environment?

I put my test_helper.rb here: http://textsnippets.com/posts/show/522

Regards,


Łukasz Piestrzeniewicz
Recce - Requirements management made simple
http://recce.com/signup
My blog: http://ragnarson.blogspot.com

def test_reject_duplicate_account_name_on_signup
log_test_name(“test_reject_duplicate_account_name_on_signup”)
… # Rest of the test goes here

How to make Test::Unit log test name automatically?

You might try using caller(0) to retrieve the current method. It’ll
need a bit of formatting to strip out the stuff you don’t need, but
that ought to be pretty easy.