hardburn has asked for the wisdom of the Perl Monks concerning the following question:
In one of merlyn's columns on Checking website health, he shows how to use Test::More's SKIP blocks to skip tests that rely on a previous test passing. For instance, before testing that the title of the returned HTML is accurate, we should make sure that the request was successful and HTML is being returned, and if not, we might as well not check the title.
However, I'm finding that a significant number of new blocks is needed to fully describe the correct behavior:
# $mech is a previously-intitlized WWW::Mechanize # instance currently holding the page I want to test SKIP: { ok( $mech->response->is_success, "Request is successful" ) or skip "Unsuccessful request", 4; SKIP: { ok( $mech->is_html, "Returns HTML" ) or skip "Didn't return HTML", 3; ok( $mech->title eq 'some title', "Returns expected title" ); my @forms = $mech->forms; SKIP: { ok( @forms >= 1, "Has at least one form" ) or skip "Need at least one form to wor +k on", 1; my ($passwd_form) = @forms; ok( $passwd_form->action eq 'example.cgi', "action goes to correct CGI" ); } } }
That's a lot of nesting, and I haven't gotten to the really important parts yet.
In noticed that in Part II of merlyn's article, he breaks the third SKIP block I show above out of the nesting and into the top-level block. However, I believe that the code I show above is the more correct approach, being that we can't assume there will be any forms if the request was unsuccessful or if it didn't return HTML.
Possible solutions:
Is there a practical way to use the current state of Test::More without side-stepping the problem? Has suggestion #3 already been done and I just haven't dug through CPAN enough to find it? If no to both the above, does anyone have suggestions on a better way to implement heavily-nested skip tests?
Update: Removed redundant is_html test.
----
: () { :|:& };:
Note: All code is untested, unless otherwise stated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Keeping SKIP Test Blocks Under Control
by Ovid (Cardinal) on Apr 12, 2004 at 16:54 UTC | |
|
Re: Keeping SKIP Test Blocks Under Control
by halley (Prior) on Apr 12, 2004 at 17:03 UTC | |
by hardburn (Abbot) on Apr 12, 2004 at 17:46 UTC | |
|
Re: Keeping SKIP Test Blocks Under Control
by adrianh (Chancellor) on Apr 12, 2004 at 17:15 UTC | |
by chromatic (Archbishop) on Apr 12, 2004 at 17:58 UTC | |
by adrianh (Chancellor) on Apr 12, 2004 at 18:44 UTC | |
|
Re: Keeping SKIP Test Blocks Under Control
by fizbin (Chaplain) on Apr 12, 2004 at 17:21 UTC | |
by merlyn (Sage) on Apr 12, 2004 at 17:37 UTC | |
by fizbin (Chaplain) on Apr 12, 2004 at 18:07 UTC | |
by hardburn (Abbot) on Apr 12, 2004 at 17:39 UTC |