TDD-test-driven
Red-> green-> refactoring
Code
# IntroductionSource codeDirectory
Use Lib " /Sdbdata/develop/src/lib/ " ;
# Introduce the package to be tested
Use Log4p;
# Number of test cases
Use Test :: More Tests => 8 ;
# Or alternately, if we don't know how well:
# Use test: More QW (no_plan );
# Test Initialization
# Check that our module compiles and can be "use" D.
Begin {use_ OK ( ' Perlnet: testme ' );}
# Check our module can be required. Very similar test to that above.
Require_ OK ( ' Perlnet: testme ' );
# There are a number of ways to generate the "OK" tests. These are:
# OK: first argument is true, second argument is name of test.
# Is: first argument equals (EQ) second argument, third argument is name of test.
# Isnt: first argument does not equal (NE) the Second, Third is name of test
# Like: first argument matches Regexp in second, third is name of test
# Unlike: first argument does not match Regexp, third is name of test
# Cmp_ OK: Compares first and third argument with comparison in second. Forth is test name.
OK (( 1 + 1 ) = 2 , " Basic addition is working " );
Is ( 2 - 1 , 1 , " Basic Subtraction is working " );
Isnt ( 2 * 2 , 5 , " Basic multiplication doesn' t fail " );
Like ( " Perlnet is great " , Qr / Perlnet / I , " Finding perlnet in a string " );
Unlike ( " Perlnet is great " , Qr / Pythonnet / I , " Not finding pythonnet in a string " );
Cmp_ OK ( $ This , ' = ' , $ That , " Comparing $ this and $ that with integer = " );