in reply to Test Driven Development example + design question

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!