An Introduction to TAP

The Test Anything Protocol (TAP) is a standard output format for test results. A producer generates TAP streams and then a consumer can read these streams and use them for different purposes. In a Java test project with TestNG, for instance, the TestNG tests would be the producer. Another tool or code that interprets the results and build reports would be the consumer.

The following is an example of a simple TAP Stream with three tests.

ok 1 - Input file opened
not ok 2
ok 3 - Read the rest of the file
# Yeah, you can comment your TAP Stream
not ok 4 - Summarized correctly # TODO Not written yet

History

TAP was created by the Perl community. It surged as the output format of the Test::Harness module and was used later by Test::More. TAP is present in Perl since Perl's first version.

In the beginning TAP didn't have this name. Actually, it didn't have any name, it was usually referred to as the Test::More protocol. No, TAP wasn't named in a Pub conversation, although it is a good place to have great ideas. TAP was named in a chat with many members of the Perl community.

The current version of the protocol is 13. The first version was committed in Perl 1 by Larry Wall on January the 30th, as part of t/TEST.

Why would you use TAP in your Java programs?

Below you will find a list with some reasons why you would use TAP in your Java programs. We only listed a few reasons, but there are other good reasons to use TAP. Just remember that if you are not integrating your test results with any other tool, then using TAP may be just waste of time.

  • You need more information in your Continuous Integration server.
  • You need to take a specific action based on a certain output property of your tests.
  • You need better control over your test execution.
  • You need to attach other files (such as log files) to your test results.
  • Your test results are going to be read by a program written in another language (specially if this language is Perl).