“Annotating” things mid-unit-test
I use JUnit, PHPUnit and Perl’s Test::Unit. Perl’s version has a very cool feature. You can call annotate(string) at any point during the test, and this text will get recorded, and only outputted in the case of the test’s failure.
sub test_foo {
my $self = shift;
my $value = setup_something();
$self->annotate("value = $value \n");
$self->assert_equals(12, do_something($value));
}
So you can just log arbitrary stuff during the test, and it will be output when you need it (when the test fails), but won’t clutter up the test output (when the test succeeds).
I wish this was available from the PHP and Java unit testing frameworks!
Not sure about this, why would you ever look at the output of a successful test?
Yeah I changed the wording; the original wording was unclear.