Skip to content

Quickstart tap test

Julio Merino edited this page Apr 13, 2015 · 1 revision

Writing a Test Anything Protocol (TAP) test

The Test Anything Protocol is documented here: http://testanything.org

Example ATF test - TAP

The following example consists of one shell script, tap-test1.sh and one Kyuafile which references the scripts. The shell script and the Kyuafile must be in the same directory.

tap-test1.sh - test program with multiple test cases

#!/bin/sh

test1()
{
    rm /nonexistent
}

test2()
{
   touch /tmp/a
}

test3()
{
   rm /tmp/a
}

test4()
{
  rm /tmp/b 
}

show_result()
{
    local result=$1
    local num=$2
    local descr="$3"

    if [ $result -ne 0 ]; then
        printf "not "
    fi
    echo "ok $num - $descr"
}

echo "1..4"

test1
show_result $? 1 "Remove /nonexistent"
test2 
show_result $? 2 "Create /tmp/a"
test3
show_result $? 3 "Remove /tmp/a"
test4
show_result $? 4 "Remove /tmp/b"

exit 0

Kyuafile

-- Comments in Kyuafiles must start with two hyphens

-- The syntax version must be defined to 2 at the
-- beginning of all Kyuafiles. 
syntax(2)

-- The name of the test suite must be defined.
test_suite('suite2')

-- This specifies the test program
atf_test_program{name='tap-test1.sh'}

#Listing the tests#

To list the tests which will be run, type:

kyua list

The output will look like this:

tap-test1.sh:main

kyua cannot list the individual TAP tests before running them, because it can only parse the test output to know how many tests there are.

Running the tests

To run the all tests, type:

kyua test

The output of the test run will look like:

tap-test1.sh:main  ->  failed: 2 tests of 4 failed  [0.015s]

Results file id is Users_crodrigues_kyua.wiki_QuickStart.20141027-214923-043078
Results saved to /home/crodrigues/.kyua/store/results.Users_crodrigues_kyua.wiki_QuickStart.20141027-214923-043078.db

0/1 passed (1 failed)

Generating test reports

After running the tests, you can generate test reports.

  • To generate a report in text format, type:

      kyua report
    
  • To generate a report in HTML format, type:

      kyua report-html
    
  • To generate a report in JUnit XML, type:

      kyua report-junit
    

Further references