Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

strengthening a fragile test

by hesco (Deacon)
on Feb 12, 2011 at 03:34 UTC ( [id://887724]=perlquestion: print w/replies, xml ) Need Help??

hesco has asked for the wisdom of the Perl Monks concerning the following question:

I published another module the other day (WWW-Scrape-Mailman-RSS-0.12) and am now responding to the feedback I'm getting from the smoke testers. Fixing the first round of issues (attempts to create a file at a path which existed only in my local environment) was easy. But I can see that the code below is about to blow up in my face.

my %args = ( 'info_url' => '', 'base_url' => '', 'list_name' => 'gpga-news', 'audience' => 'Greens', 'description' => 'News by, about and for Greens', 'cycles' => 2, 'output_file' => 't/tmp/gpga_news_feed.html', 'rss_output' => 't/tmp/gpga_news_feed.rss', 'template' => 't/tmpl/gpga_news_feed.tmpl', ); my $news_feed = $feed->render_feed(\%args); # this is fragile and will break in two weeks my $latest_month = '2011-February'; my $next_latest_month = '2011-January'; like($news_feed,qr/$latest_month/,'Feed includes latest month'); like($news_feed,qr/$next_latest_month/,'it also includes the second mo +st recent month');
In fact, even if I could generate the $latest_month and $next_latest_month programmatically, this test would still fail from midnight the morning of the 1st of each month until the first post was archived to the test list each month.

Can someone please advise how I might make this test less fragile, please? Mocking it seems not quite right, because part of what I need to test is my ability to give this object an $args{'base_url'} and get back an rss feed.

-- Hugh

if( $lal && $lol ) { $life++; }
if( $insurance->rationing() ) { $people->die(); }

Replies are listed 'Best First'.
Re: strengthening a fragile test
by Corion (Patriarch) on Feb 12, 2011 at 09:10 UTC

    I'm not sure whether your module has to create things with "today's date", but if not, why not ship canned HTML files with a fixed date, and use these in your tests?

Re: strengthening a fragile test
by Anonymous Monk on Feb 12, 2011 at 06:19 UTC

    There are any number of date modules you can use to sort out the needed values. I prefer Date::Calc myself, but others have different views.

    I don't see why the code should fall over if you calculate the months just before you use them. That's what I usually do.

Re: strengthening a fragile test
by budman (Sexton) on Feb 13, 2011 at 08:24 UTC
    What about sampling dates and then checking to see if the requested date is available.
    use strict; use Date::Calc qw(Today Add_Delta_YM Month_to_Text); my @today=Today(); my $months_back; my @fetchDates; while ( @fetchDates < 2 ) { my @calcDate = Add_Delta_YM(@today[0,1],1,0,$months_back); my $date_str = $calcDate[0] .'-'. Month_to_Text($calcDate[1]); if ( &dateAvailable($date_str) ) { push @fetchDates, $date_str } $months_back--; } print "Retrieving dates:\n".join("\n",@fetchDates)."\n"; sub dateAvailable { my $date = shift; # check site of date can be downloaded return int(rand(2)); }
    I used rand just to show how it would work

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://887724]
Approved by toolic
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-24 02:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found