mp has asked for the wisdom of the Perl Monks concerning the following question:
In writing these tests, I've been migrating to a data-driven structure like the code below. This has factored out some of the repetitive code, but I think there is room for further improvement. My goal is to end up with test scripts that are largely self-documenting in terms of what actions are being performed and what results are being tested and that have little repeated code.
Does anyone see a different approach that would be a better fit? Does anyone have any useful references on data-driven programming in perl? I have turned up very little with google and super-search.
... my $mech = WWW::Mechanize->new(...); my $question = { 1 => 'value_12345', 2 => 'value_12346', 3 => 'value_12347', }; my $test_list = [ { name => 'First page of sequence', check_list => [ # Things to compare content to on this page [ qr/Some text/, "test name" ], ], action => sub { # Action to perform from this page $mech->click; }, }, { name => 'page seen after first click', check_list => [ [ qr/Dst1/, "destination1" ], ], action => sub { $mech->submit_form( fields => { $question->{1} => 3, # Q1, choice 3 (radio button) }); }, }, { name => 'page seen after second POST', check_list => [ [ qr/Dst2/, "destination2" ], [ qr/more text/, "more text expected on this page" ], ], action => sub { $mech->submit_form( fields => { $mech->back; $mech->back; }); }, }, ]; $mech->get(qq[some_uri]); my $verbose = 0; for my $test(@$test_list) { my $name = $test->{name}; my $check_list = $test->{check_list}; for my $check(@$check_list) { like($mech->content, $check->[0], "test $name - $check->[1]"); } diag $mech->current_form->dump if $verbose; if ($test->{action}) { $test->{action}->(); } sleep 1; # Optional }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Data-driven programming with WWW::Mechanize
by Aristotle (Chancellor) on Sep 08, 2004 at 23:31 UTC | |
Re: Data-driven programming with WWW::Mechanize
by johnnywang (Priest) on Sep 08, 2004 at 18:47 UTC |