-
9
pages
-
English
-
Documents
Description
Test::TutorialNAMETest::Tutorial - A tutorial about writing really basic testsDESCRIPTIONAHHHHHHH!!!! NOT TESTING! Anything but testing! Beat me, whip me, send me to Detroit, but don’tmake me write tests!*sob*Besides, I don’t know how to write the damned things.Is this you? Is writing tests right up there with writing documentation and having your fingernails pulledout? Did you open up a test and read######## We start with some black magicand decide that's quite enough for you?It's ok. That's all gone now. We've done all the black magic for you. And here are the tricks...Nuts and bolts of testing.Here's the most basic test program.#!/usr/bin/perl -wprint "1..1\n";print 1 + 1 == 2 ? "ok 1\n" : "not ok 1\n";since 1 + 1 is 2, it prints:1..1ok 1What this says is:1..1 "I'm going to run one test." [1]ok 1 "The first test passed". And that's aboutall magic there is to testing. Your basic unit of testing is the ok. For each thing you test, anok isprinted. Simple. Test::Harness interprets your test results to determine if you succeeded or failed(more on that later).Writing all these print statements rapidly gets tedious. Fortunately, there's Test::Simple. It has onefunction,ok().#!/usr/bin/perl -wuse Test::Simple tests => 1;ok( 1 + 1 == 2 );and that does the same thing as the code above.ok() is the backbone of Perl testing, and we'll beusing it instead of roll your own from here on. Ifok() gets a true value, the test passes. False, it fails.#!/usr ...
-
Publié par
-
Langue
English