Skip to content

Test Harness

gaiaops edited this page Jan 25, 2012 · 3 revisions

Gaia Tap Test harness

The test harness we use is a php script that generates TAP output.

http://en.wikipedia.org/wiki/Test_Anything_Protocol

You can run the script by hand from the unix command line prompt. The first line outputs the number of tests expected to run. Each subsequent line begins with an 'ok' followed by the sequence number of the test.

You could generate a TAP compliant script in php by doing the following:

#!/usr/bin/env php
<?php
echo "1..1\n";
echo "ok 1 this test works!\n"

The code in lib/gaia/test/tap.php provides an easy way to generate this output for you in a consistent way and to handle the error cases. This is best illustrated with an example:

#!/usr/bin/env php
<?php
include __DIR__ .'/gaia_core_php/autoload.php';
use Gaia\Test\Tap;
Tap::plan(1);
Tap::ok(true, 'this test works');

Now that my script generates TAP compliant output I can use the perl prove test harness to scan all the test files in a given directory and verify the tests all pass:

http://search.cpan.org/~andya/Test-Harness-3.23/bin/prove

I run a recursive prove command on my tests directory:

prove -r ./tests/
./tests/demo.t .. ok   
All tests successful.
Files=1, Tests=1,  1 wallclock secs ( 0.03 usr  0.00 sys +  0.02 cusr  0.02 csys =  0.07 CPU)
Result: PASS

This finds any executable files in the tests directory or any nested directories with a .t file extension and runs it, and parses the output to make sure it works

Now I can start writing tests in my file to make sure they all are true.

Clone this wiki locally