Testing Perl programs for beginners. Test Anything Protocol (TAP)

    Before I move on to describing how to work with the modules Test :: More, Test :: Harness and Test :: Simple, I would like to clarify what TAP is - a mention of which appears from time to time when discussing the topic of testing programs.

    The text of this topic is basically a translation of a suitable text from Wikipedia (link below).
    Perhaps the only material in this topic that I practically did not undergo any
    processing except translation. :)


    Test Anything Protocol (TAP) is a single format for transmitting test results to programs that interpret the 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.

    Basic TAP format:
    1..N
    ok 1 Description # Directive
    # Diagnostic
    ...
    ok 47 Description
    ok 48 Description
    more tests ...


    For example, testing the reading of data from a file could give the following result:
    1..4
    ok 1 - Input file opened
    not ok 2 - First line of the 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. Advantages of this approach:
    • the ability to write tests in different programming languages ​​that will send the results to a common processor for analysis and reporting;
    • use of uniform rules for displaying test results:
      1. the programmer does not need to worry about the format of the report output, their appearance, creating a convenient interface for interacting with the test.
      2. the results of all tests are passed to a common processor, which is responsible for the standard appearance and format of reports.
    • after writing the next test, the programmer makes a link to the new file in the handler code. Upon receipt of the appropriate command, the handler automatically launches all previously specified testing scripts. Accordingly, the programmer is freed from the need to manually run each test for execution (if there are more than 20 test files and tests are carried out regularly, significant time savings appear.)


    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 an analyzer included in the Perl source code.
    • TAP :: Parser is one of the latest and most flexible analyzers. It was previously called TAPx :: Parser.
    • Test :: Run - an analyzer that became a branch of Test :: Harness.
    • test-harness.php - TAP analyzer for PHP.


    Libraries for working with TAP


    A list of libraries designed to write tests and output data in TAP format.

    • Test :: More is the most popular Perl module for creating tests.
    • PHPUnit - The JUnit port in PHP. The environment for writing tests in PHP.
    • test-more.php - a module for creating tests in PHP, created on the basis of Test :: More.
    • libtap is a TAP library written in C.
    • Test.Simple - port of Test :: Simple (Perl) and Test :: More modules in JavaScript.
    • PyTAP is a library for working with TAP, for Python.
    • MyTAP is the MySQL test library, used to write TAP procedures in C or C ++.


    useful links


    RUS

    Writing automated tests and phpUnit

    ENG environment

    http://en.wikipedia.org/wiki/Test_Anything_Protocol
    testanything.org. Specialized TAP Resource

    Also popular now: