Skip to content

Quickstart plain test

Julio Merino edited this page Apr 13, 2015 · 2 revisions

Writing a plain test

A plain test reports its status to kyua via its exit status code:

  • 0 exit status means the test succeeded.
  • non-zero exit status means the test failed.

Plain test programs can be written in any programming language, such as shell script, C, C++, Python, Ruby, etc.

Example plain test

The following example consists of two shell scripts and one Kyuafile which references both scripts. The shell scripts and the Kyuafile must be in the same directory.

Here is a simple test program that succeeds returns an exit status of 0.

test1.sh - test program which reports success

#!/bin/sh

# test1.sh

echo "Test 1: Testing equality"

if [ 1 -eq 1 ]
then
   exit 0
else
   exit 99
fi

Here is another test program that fails with a non-zero exit status.

test2.sh - test program which reports failure

#!/bin/sh

# test2.sh

echo "Test 2: testing for existence of file"

if [ -e /somerandomfile ]; then
    echo "/somerandomfile exists"
    exit 0
else
    echo "/somerandomfile does not exist"
    exit 1
fi

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('suite1')

-- This specifies the test programs
plain_test_program{name='test1.sh'}
plain_test_program{name='test2.sh'}

Listing the tests

To list the tests which will be run, type:

kyua list

The output will look like this:

test1.sh:main
test2.sh:main

Running the tests

To run the all tests, type:

kyua test

The output of the test run will look like:

test1.sh:main  ->  passed  [0.004s]
test2.sh:main  ->  failed: Returned non-success exit status 1  [0.004s]

Results file id is usr_home_crodrigues_kyua-quickstart_kyua.wiki_QuickStart.20141008-223917-630841
Results saved to /home/crodrigues/.kyua/store/results.usr_home_crodrigues_kyua-quickstart_kyua.wiki_QuickStart.20141008-223917-630841.db

1/2 passed (1 failed)

To run only the first test, type:

kyua test test1.sh:main

The output of the test run will look like:

test1.sh:main  ->  passed  [0.004s]

Results file id is usr_home_crodrigues_kyua-quickstart_kyua.wiki_QuickStart.20141008-230542-335139
Results saved to /home/crodrigues/.kyua/store/results.usr_home_crodrigues_kyua-quickstart_kyua.wiki_QuickStart.20141008-230542-335139.db

1/1 passed (0 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