Test Suite Organization
I've written about this before, but now I want to show some slides from my new testing class because I think it's easier to show test suite organization rather than describe it.
Years ago I wrote HTML::TokeParser::Simple, an OO interface to HTML::TokeParser. The latter is a great module, but you are typically working with a bunch of array references like this:
["S", $tag, $attr, $attrseq, $text]
["E", $tag, $text]
["T", $text, $is_data]
["C", $text]
["D", $text]
["PI", $token0, $text]
That can be confusing and you often have to write code that is hard to immediately understand. For example, here's the code to strip all comments from an HTML document:
while (my $token = $p->get_token) {
next if 'C' eq $token->[0];
say $token->[-1];
}
That small snippet isn't too bad, but when you're doing complex work with HTML documents, it can become hairy. Here's how HTML::TokeParser::Simple
works:
while (my $token = $p->get_token) {
next if $token->is_comment;
say $token->as_is; # not brilliant, but there you go
}
The test suite, however, is a bit of a problem.