Test Anything Protocol
Encyclopedia
The Test Anything Protocol (TAP) is a protocol to allow communication between unit test
s and a test harness
. It allows individual tests (TAP producers) to communicate test results to the testing harness in a language-agnostic way. Originally developed for unit testing of the Perl
interpreter in 1987, producers and parsers are now available for many development platforms.
was written by Tim Bunce and Andreas König to allow Perl module authors to take advantage of TAP.
Development of TAP, including standardization of the protocol, writing of test producers and consumers, and evangelizing the language is coordinated at the TestAnything website.
.
A project to produce an IETF standard for TAP was initiated in August 2008, at YAPC::Europe 2008..
For example, a test file's output might look like:
Unit test
In computer programming, unit testing is a method by which individual units of source code are tested to determine if they are fit for use.A unit is the smallest testable part of an application. In procedural programming a unit could be an entire module but is more commonly an individual function...
s and a test harness
Test harness
In software testing, a test harness or automated test framework is a collection of software and test data configured to test a program unit by running it under varying conditions and monitoring its behavior and outputs. It has two main parts: the Test execution engine and the Test script...
. It allows individual tests (TAP producers) to communicate test results to the testing harness in a language-agnostic way. Originally developed for unit testing of the Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
interpreter in 1987, producers and parsers are now available for many development platforms.
History
TAP was created for the first version of Perl (released in 1987), as part of the Perl's core test harness (t/TEST). The Test::Harness modulePerl module
A Perl module is a discrete component of software for the Perl programming language. Technically, it is a particular set of conventions for using Perl's package mechanism that has become universally adopted....
was written by Tim Bunce and Andreas König to allow Perl module authors to take advantage of TAP.
Development of TAP, including standardization of the protocol, writing of test producers and consumers, and evangelizing the language is coordinated at the TestAnything website.
Specification
Despite being about 20 years old and widely used, no formal specification exists for this protocol. The behavior of the Test::Harness module is the de-facto TAP standard, along with a writeup of the specification on CPANCPAN
CPAN, the Comprehensive Perl Archive Network, is an archive of nearly 100,000 modules of software written in Perl, as well as documentation for it. It has a presence on the World Wide Web at and is mirrored worldwide at more than 200 locations...
.
A project to produce an IETF standard for TAP was initiated in August 2008, at YAPC::Europe 2008..
Usage examples
TAP's general format is:
1..N
ok 1 Description # Directive
# Diagnostic
....
ok 47 Description
ok 48 Description
more tests....
For example, a test file's output might look like:
1..4
ok 1 - Input file opened
not ok 2 - First line of the input valid.
More output from test 2. There can be
arbitrary number of lines for any output
so long as there is at least some kind
of whitespace at beginning of line.
ok 3 - Read the rest of the file
#TAP meta information
not ok 4 - Summarized correctly # TODO Not written yet
External links
- http://testanything.org/ is a site dedicated to the discussion, development and promotion of TAP.
List of TAP Parsers
These are libraries which parse TAP and display the results.- Test::Harness is the oldest and most complete TAP parser. It is limited in how it displays TAP. Though it most often runs tests written in Perl, it can launch any process which generates TAP. Most of the TAP spec is taken from the behavior of Test::Harness.
- The original Test::Harness has now been deprecated, the new Test::Harness provides a minimal compatibility layer with previous behavior, but any new development shouldn't use this module, rather the TAP::Harness module.
- The t/TEST parser contained in the Perl source code.
- Test::Harness is a new and more flexible parser being written by Curtis "Ovid" Poe, Andy Armstrong and other people. It is a wrapper around TAP::Parser.
- Test::Run is a fork of Test::Harness being written by Shlomi Fish.
- test-harness.php A TAP parser for PHP.
- nqpTAP A TAP parser written in NotQuitePerl (NQP), a smaller subset of the Perl 6 language.
- Tapir A TAP parser written in Parrot Intermediate RepresentationParrot intermediate representationThe Parrot intermediate representation , previously called Intermediate code , is one of the two assembly languages for the Parrot virtual machine. The other is Parrot assembly language or PASM...
(PIR). - tap4j A TAP implementation for Java.
List of TAP Producers
These are libraries for writing tests which output TAP.- Test::More is the most popular testing module for Perl 5.
- Test::Most puts the most commonly used Perl 5 testing modules needed in one place. It is a superset of Test::More.
- PHPUnit is the xUnit implementation for PHP.
- test-more.php is a testing module for PHP based on Test::More.
- test-more-php implements Test::Simple & Test::More for PHP.
- libtap is a TAP producer written in C.
- libtap++ is a TAP producer for C++
- Test.Simple is a port of the Perl Test::Simple and Test::More modules to JavaScript by David Wheeler.
- PyTAP A beginning TAP implementation for Python.
- MyTAP MySQL unit test library used for writing TAP producers in C or C++
- Bacon A Ruby library that supports a spec-based syntax and that can produce TAP output
- PLUTO PL/SQL Unit Testing for Oracle
- pgTAP PostgreSQL stored procedures that emit TAP
- SnapTest A PHP unit testing framework with TAP v13 compliant output.
- etap is a simple erlang testing library that provides TAP compliant output.
- lua-TestMore is a port of the Perl Test::More framework to Lua.
- tap4j A TAP implementation for Java.
- lime A testing framework bundled with the Symfony PHP framework.
- yuitest A JavaScript testing library (standalone)