I have a different view of TDD. First, use a bare minimum of lines and keep your structures simple at first because you want a minimal skeleton of a test to "fail": Remember to fail first, then write a minimal fix. Take it one small step at a time.

I usually start by writing POD. Put your ideas down in words. Then I use Test::XT. For example, I wrote some POD using some of your ideas:
package Calculator::ForMyExperiment use strict; use warnings; =head1 NAME Calculator::ForMyExperiment - calculate simple stuff =head1 VERSION version 0.01 =cut our $VERSION = '0.01'; =head1 SYNOPSIS use Calculator::ForMyExperiment my $data = Calculator::FroMyExperiment->new; my $doit = calculate_simple_stuff($experiment); =head1 DESCRIPTION This module has a function for calculating stuff. =head1 EXPORTS The calculate_simple_stuff function is exported by default. =cut require Exporter; require DynaLoader; our (@ISA) = qw( Exporter DynaLoader); our (@EXPORT_OK) = qw( calculate_simple_stuff ); bootstrap Calculator::ForMyExperiment $VERSION; =head1 FUNCTIONS =head2 calculate_simple_stuff Merges simple stuff. =cut sub new { my $class = "Calculator::ForMyExperiment"; my %params = @_; my $self = {}; bless $self, $class; return $self; } sub calculate_simple_stuff { my($stuff) = qw/one two three/; foreach $stuff( my @stuffing ) { $stuff = shift(); print $stuff; } 1;
Now use Test::XT to write a test for pod syntax:
#!/usr/bin/perl use strict; use warnings; use Test::XT 'WriteXT'; my $test = Test::XT->new( test => 'all_pod_files_ok', release => 0, comment => 'Test that the syntax of the POD documentation is valid +', modules => { 'Pod::Simple' => 0, 'Test::Pod' => 0, }, default => 't/pod.t', ); $test->module( 'Spreadsheet::WriteExcel' ); $test->test( 'all_pod_coverage_ok' ); print "Test script: "; print $test->write_string;
The resulting output:
#!/usr/bin/perl -l # Test that the syntax of the POD documentaion is valid use strict; BEGIN { $| = 1; $^W = 1; } my @MODULES = ( 'Pod::Simple' => 0, 'Test::Pod' => 0, 'Spreadsheet::WriteExcel" => 0, ); # Don't run tests during end-user installs use Test::More; plan( skip_all => 'Author tests not required for installation' ) unless ( $ENV{RELEASE_TESTING} or $ENV{AUTOMATED_TESTING} ); # Load the testing modules foreach my $MODULE ( @MODULES ) { eval "use $MODULE"; if ( $@ ) { $ENV{RELEASE_TESTING} ? die( "Failed to load required release-testing module $MODULE" ) : plan( skip_all => "$MODULE not available for testing" ); } } all_pod_coverage_ok(); 1;
Now you're good to go!

In reply to Re: Test Driven Development example + design question by Khen1950fx
in thread Test Driven Development example + design question by mascip

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.