Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Great post, hippo!

Like haukex, I've just got a couple of suggestions. I'll stay away from more advanced testing functionality as this is a "Basic" tutorial.

Ensuring things die() when you expect them to, in combination of the like() and is() functions. If the call within the eval() succeeds, the 1 will be returned. If not, it dies, and the eval() returns undef:

for (-1, 4096){ is eval { $e->read($_); 1; }, undef, "read() with $_ as addr param fails"; like $@, qr/address parameter out of range/, "...and error is sane +"; }

Always use sane test messages, so that it's trivially easy to see the output and quickly identify in your test script where the test actually is. In the above, it specifies exactly what I'm testing (read()), it states that I'm specifically testing the addr param, and even signifies which iteration of the loop did/didn't break ($_).

How to use skip. This is a basic piece of functionality that a blooming unit test writer needs to know. There are several ways and reasons to use this, but I'll stick to the most basic premises:

Skip all tests in a file for any reason:

plan skip_all => "i2c bus currently disabled for other purposes";

Skip all tests in a file based on external flag:

if (! $ENV{SERIAL_ATTACHED}){ plan skip_all => "The damned serial port shorted out!"; }

Skip all tests in a file if certain software isn't installed (stolen from a POD test):

my $min_tpc = 1.08; eval "use Test::Pod::Coverage $min_tpc"; plan skip_all => "Test::Pod::Coverage $min_tpc required for testing PO +D coverage" if $@;

Speaking of testing, yesterday I reached the 10,000 test mark on one of my larger, more elaborate projects :)

Files=61, Tests=10032, 586 wallclock secs ( 8.68 usr  0.50 sys + 149.28 cusr  8.14 csys = 166.60 CPU)

In reply to Re: RFC: Basic Testing Tutorial by stevieb
in thread RFC: Basic Testing Tutorial by hippo

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (5)
    As of 2020-02-18 20:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?










      Results (79 votes). Check out past polls.

      Notices?