Fork me on GitHub

Project Notes

#454 Test::Simple

The basics of Perl testing with the Test::Simple module.

Notes

The Perl Test::Simple module is an extremely simple, extremely basic module for writing tests for Perl projects and modules.

See also: Perl Testing - Chapter 1: Beginning Testing.

Module installation:

$ cpan Test::Simple
Loading internal logger. Log::Log4perl recommended for better logging
Reading '/Users/paulgallagher/.cpan/Metadata'
  Database was generated on Fri, 08 May 2026 02:17:02 GMT
Test::Simple is up to date (1.302219).

A Basic Test File

Given a simple script hello.pl:

#!/usr/bin/env perl
#
use strict;
use warnings;

sub hello_world {
  return "Hello, World!";
}

print hello_world(), "\n" if !caller();

1;

When run interactively, it simply prints the result of the hello_world function:

$ ./hello.pl
Hello, World!

Let’s write some tests in hello.t:

#!/usr/bin/env perl
#
use strict;
use warnings;

use lib ".";
require 'hello.pl';

use Test::Simple tests => 1;

ok( hello_world() eq "Hello, World!", 'hello_world output should be sane');

NB: if we don’t know or care how many tests to expect, can declare with no plan: use Test::Simple 'no_plan';

Tests are run with prove:

$ prove hello.t
hello.t .. ok
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.01 usr  0.01 sys +  0.01 cusr  0.00 csys =  0.03 CPU)
Result: PASS
$ prove -v hello.t
hello.t ..
1..1
ok 1 - hello_world output should be sane
ok
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.01 usr  0.00 sys +  0.01 cusr  0.00 csys =  0.02 CPU)
Result: PASS

Credits and References

About LCK#454
Perl

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

Project Source on GitHub Return to the LittleCodingKata Catalog
About LittleCodingKata

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

Follow the Blog follow projects and notes as they are published in your favourite feed reader