in reply to Re: TDD with Coverage Analysis. Wow.
in thread TDD with Coverage Analysis. Wow.
For example, ... what kind of coverage does this get:If you're a coverage junkie, then you might put yourself through all sorts of contortions to eliminate that red spot ... But why?open( my $fh, ">", $output ) or die_with_error();
One reason to make sure that the error branch is tested is for documentation. You're showing the (test) reader how the method under test behaves when it encounters that error. Having tested die_with_error() isn't sufficient. That leaves the reader in the position of having to read both the test, the code being tested, and whatever methods or subs that code invokes.
It might also be possible that in the context of the line of code above, invoking die_with_error() might be the wrong thing to do. And, admit it, that "or" branch might never get invoked during testing unless you force the issue.
Besides, the contortions here are minor. If $output is an argument to the method you're testing, injecting a bogus file path is trivial. And if doing that involves too many other side effects, it's a hint that extracting that line (and possibly some others around it that are involved in setting up for output) into a separate, more easily testable method might simplify the code.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: TDD with Coverage Analysis. Wow.
by xdg (Monsignor) on Aug 28, 2005 at 06:07 UTC | |
by dws (Chancellor) on Aug 28, 2005 at 19:04 UTC | |
by adrianh (Chancellor) on Aug 28, 2005 at 09:50 UTC |