-
Notifications
You must be signed in to change notification settings - Fork 42
Quickstart 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.
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.
#!/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.
#!/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
-- 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'}
To list the tests which will be run, type:
kyua list
The output will look like this:
test1.sh:main
test2.sh:main
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)
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
- kyua plain interface man page
- The FreeBSD source tree has a heavily commented example plain test program.