Testing Perl programs for beginners. Test Anything Protocol (TAP)
Before I turn to the description of the work with the modules Test :: More, Test :: Harness and Test :: Simple, I would like to clarify what TAP is - mentioning which, from time to time, appears when discussing the topic of program testing.
The text of this topic is basically a translation of the appropriate text from Wikipedia (link below). Perhaps the only material in this topic that I have practically not been exposed to. processing other than translation.:)
Test Anything Protocol (TAP) is a uniform format for transmitting test results to programs that interpret results, and depending on them, perform some actions. A simpler definition is a single format for displaying test results . ')
TAP is not tied to a specific programming language, however, it is most often used by Perl programmers.
The main TAP format:
1..N ok 1 Description # Directive # Diagnostic ... ok 47 Description ok 48 Description more tests ...
For example, testing reading data from a file might give the following result:
1..4 ok 1 - Input file opened not ok 2 - First line of input valid ok 3 - Read the rest of the file not ok 4 - Summarized correctly # TODO Not written yet
Using TAP allows you to separate the test program from the program that automatically runs test scripts, receives and processes the results, analyzes them. The advantages of this approach:
the ability to write tests in different programming languages that will send the results to a common processor for analyzing and generating reports;
use common rules for displaying test results:
the programmer does not need to worry about the output format of the reports, their appearance, the creation of a convenient interface for interacting with the test.
The results of the execution of all tests are transmitted to the general processor, which is responsible for the standard appearance and format of the reports.
after writing the next test, the programmer inserts a link to the new file in the handler code. When a corresponding command is received, the handler automatically runs all previously specified testing scripts for execution. Accordingly, the programmer is relieved of the need to manually run each test for execution (if the test files are over 20, and the tests are conducted regularly, there is a significant time saving.)
TAP analyzers
A list of libraries (modules) that are designed to analyze TAP and publish test results.
Test :: Harness is the oldest and most comprehensive TAP analyzer. Most often works with tests written in Perl.
t / TEST is the analyzer included in the Perl source code.
TAP :: Parser is one of the newest and most flexible analyzers. Previously, it was called TAPx :: Parser.
Test :: Run - an analyzer that became an offshoot of Test :: Harness.
test-harness.php - TAP analyzer for PHP.
TAP Libraries
List of libraries intended for writing tests and performing data output in TAP format.
Test :: More is the most popular Perl module for creating tests.
PHPUnit is the JUnit port in PHP. The environment for writing tests for PHP.
test-more.php - module for creating tests for PHP, created on the basis of Test :: More.
libtap is a library for working with TAP, written in C.
Test.Simple - port Test :: Simple (Perl) and Test :: More modules in JavaScript.
PyTAP is a library for working with TAP, for Python.
MyTAP is a MySQL test library used to write TAP procedures in C or C ++.