2 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

You are here

PerlUnit

An xUnit Testing Framework for Perl Language

Tool Information

Introduction

Tool Summary

PerlUnit PerlUnit - an xUnit Testing Framework for Perl language. PerlUnit is now a project on sourceforge. 

Last Release Year ['Active'=Current]: 
Active
Since (maturity): 
2005

 

PerlUnit
 an xUnit TestingFramework for PerlLanguage Tool Scope Testing Tool
Application Rights Free Use, Opensource
Since 2005
Company Sourceforge
Support Tool Support link HERE
Download Download HERE
Files & Media

Media & Files

Additional Information: 

How Perl Module Testing Works

This section assumes you're already familiar with perlmodinstall, having installed a module manually. After the perl Makefile.PL and make stages, make test runs any tests shipped with the module, either test.pl or all files in the t/ directory that end in ``.t.'' The blib/ directories are added to @INC, and Test::Harness runs the test files, captures their output and provides a short summary of the results, including success and failure.

At its heart, a test either prints ``ok'' or ``not ok.'' That's it. Any test program or testing framework that prints results to standard output can use Test::Harness. If you're feeling epistemological (a good trait to cultivate for writing tests), you could ask ``What is truth?'':

print "1..1\n"; if (1) { print "ok\n"; } else { print "not ok\n"; }

Basic? Yes. Bogus? Not really. This is a variant of an actual Perl core test. If you understood that code, then you can write tests. Ignoring the first line for now, simply stick it in a file (truth.t) and run either the command line:

perl -MTest::Harness -e "runtests 'truth.t'";

or the program:

#!/usr/bin/perl -w use strict; use Test::Harness; runtests 'truth.t';

This should produce a message saying that all tests succeeded. If not, then something is broken, and many people would be interested in fixing it.

The first line of the test corresponds to Test::Harness' handy test-numbering feature. The harness needs to know how many tests to expect, and each individual test within a group can have its own number. This is for your benefit. If one test in a 100 mysteriously fails, then it's much easier to track down number 93 than it is to run through the debugger, comment out large swaths of the test suite or rely on intuitively placed print statements.

Knowing truth is good, and so is discerning falsehood. Let's extend truth.t slightly. Note the addition of test numbers to each potential printable line. This is both a boon and a bane.

print "1..2\n"; if (1) { print "ok 1\n"; } else { print "not ok 1\n"; } if (0) { print "not ok 2\n"; } else { print "ok 2\n"; }

Besides the increasingly duplicate code, keeping test numbers synchronized is painful. False laziness is painful -- Test::Harness emits warnings if the number of actual tests run does not meet its expectations. Test writers may not mind, but spurious warnings will confuse end users and healthily lazy developers. As a rule, the simpler the output, the more people will believe that things succeeded. The stuffed, smiling Pikachu (hey, it was a birthday present from an attractive female Web designer) perched atop my monitor makes me think that a giant yellow smiley face would be even better than a simple ``ok'' message. ASCII artists, fire up your editors!

Unfortunately, the truth test is repetitive and fragile. Adding a third test between the first two (the progression from ``truth'' to ``hidden truth'' to ``falsehood'' makes sense) means duplicating the if/else block and renumbering the previously second test. There's also room for a subtle bug:

print "1..2\n";

if (1) { print "ok 1\n"; } else { print "not ok 1\n"; }

if ('0 but true') { print "ok 2\n"; } else { print "not ok 2\n"; }

if (0) { print "not ok 3\n"; } else { print "ok 3\n"; }

Forgetting to update the first line is common. Two tests were expected; three tests ran. The confused Test::Harness will report strange things, like negative failure percentages. Baby Pikachu may cry. Smarter programmers eventually apply good programming style, writing their own ok() functions:

print "1..3\n";

my $testnum = 1; sub ok { my $condition = shift; print $condition ? "ok $testnum\n" : "not ok $testnum\n"; $testnum++; }

ok( 1 ); ok( '0 but true' ); ok( ! 0 );

The lowest levels of the Perl core test suite use this approach. It's simpler to write and handles numbering almost automatically. It lacks some features, though, and is little easier to debug.

Was This Helpful?: 
Vote up!
Vote down!

Points: 0

You voted ‘up’

MANUFACTURERS Wallboard

Testing tool manufacturers world-wide list
10Levels ABID CONSULTING AccelQ Accord Software ActiMind AdaCore
AdaLog AgileLoad AgileWay Agitar Algorismi ALL4TEC
Android Apache Apica Apollo Systems AppAssist.mobi Applitools
AppPerfect Appsee ApTest Assertible Assure Atlassian
AutoIt Consulti .. Automation Anyw .. Automation Cons .. Aztaz Software Backtrace I/O Badboy
BlazeMeter Borvid BrowserStack BSQUARE BStriker Intern .. CA Technologies
Canonical Canoo Catch Limited CelestialTeapot Celtic Testing .. Chris Mallett
Cleanscape ClicTest CloudQA CodeCentrix CodePlex projec .. Codoid
Cogitek Compuware Configure IT Conflair ConSol Core Services
Countersoft CresTech Softwa .. Cross Browser T .. Crosscheck Netw .. Crowdsourced Te .. Cucumber Ltd
Cyara Cygnet Infotech DareBoost Databene Datamatics Glob .. DevExpress
DTM soft Dynatrace LLC EasyQA Eclipse EKA TechServ Elvior
Emmanuel Jorge Empirix EPAM Systems Equafy Esterel Technol .. eXept Software ..
Experitest Finaris Froglogic FrontEndART Ltd GeneXus GitHub project
gnoso Google Code Pro .. GrammaTech Gurock Software Hewlett Packard .. Hexawise
High-Tech Bridg .. Hiptest Hitex IBM Rational imbus Shanghai Impetus
Inflectra informUp INTALIO intechnica InTENSO - IT Ex .. Ipswitch
Jamo Solutions JANOVA JAR Technologie .. JBoss Developer jClarity Jellly.io
JetBrains Jively jQuery foundati .. JS Foundation Jspresso Kanoah Software
KMS Technology Kualitee LDRA Limited Litmus LoadFocus Loadster Perfor ..
MarathonITE Marketcircle Marketcircle Maveryx Meliora Ltd Micro Focus Sof ..
Microsoft Mobile Labs Mobile1st Mockaroo, LLC ModalLogic IT Monkop Inc
Mozila MSys Technologi .. Navicat NeoTys NetCart Netvantage Tech ..
NORIZZK.COM Novosync Mobili .. NRG Global NTT Resonant OC Systems Odin Technology
OpCord Oracle Orcanos Original Softwa .. Ossia Conseil OW2
PANAYA Parasoft PassMark Patterson Consu .. Perfecto Mobile Pivotal, Inc.
Plutora Polarion Postman (API To .. PractiTest PrimaTest Process One
Programming Res .. Psoda PureLoad PushToTest Python Q-Assurance
QA Systems QACube QASymphony QAWorks QMetry Quali
QualiTest Qualitia Softwa .. Quality First S .. Quotium RadView Softwar .. Ranorex
RedLine13 Reflective Solu .. ReQtest RevDeBug Robotium Tech Rogue Wave Soft ..
Rommana Softwar .. RTTS ruby-doc.org Runscope Sandklef GNU La .. Sauce Labs
Seapine Softwar .. SeleniumHQ Sencha Sensiple SmartBear Softw .. SmarteSoft
SOASTA SoftLogica Softomotive Softsmith Solution-Soft SonarSource
Sourceforge SqashTeam SQS Software Qu .. Square Stimulus Techno .. Swifting AB
Synopsys T-komp T-Plan TechExcel TechTalk Telerik By Prog ..
Tellurium Test Collab Test Goat Test Recon TestCaseLab testCloud.de Gm ..
Testenium Testim.io Testing Technol .. TestingBot TestLodge Testmunk
TestObject GmbH TestOptimal TestPlant TestPro Testuff The Core Bankin ..
The MathWorks The Open Group thePHP.cc Thoughtbot Thoughtworks Tigris.org
Time Simulator Top-Q Trace Technolog .. TrendIC TRICENTIS Tritusa Pty Ltd
TWD Solutions P .. TypeMock Tyto Software Ubertesters UniTESK Universal Test ..
Usetrace Ltd Utrecht Univers .. Validata Group Vanamco AG Vector Software Veracode
Verifaya Corpor .. Verit VersionOne Viewlike.us Vornex Inc. Watir.com
WcfStorm Soluti .. We Are Mammoth Web Performance .. Wikidi Wintask Wireshark Found ..
Worksoft Xceptance XebiaLabs XK72 Xpand IT XQual
YesSo ZAPTEST Zeenyx Software .. Zephyr Zeta Software zutubi pty

Theme by Danetsoft and Danang Probo Sayekti