Test Anything Protocol for RobotC. Basically a bunch of unit test helper functions, that outputs to the debug stream.
- Click Download Zip.
- Copy the
tap.c
file to the directory that you want to test. - Create a unit test file, maybe
test.c
, orrun_Tests.c
. - In the file, write
#include "tap.c"
. - Use the Functions provided.
- Compile and run your unit test file.
#include "tap.c"
task main() {
tTest("the test suite works");
tOk(true);
tNotOk(false, "not ok ever!");
tEqual(17, 83-66, "83-56=17");
tNotEqual(10, 100, "ten ain't a hundred!");
tPass("oh yes");
tTest("this is the second test");
tFail("failing # TODO make this not fail");
tFail("skipping # SKIP make this skip");
tTest("the test suite works");
tEqual(17, 17, "17=17");
tEqual(10, 10, "ten ain't a hundred!");
tPass("such win");
tEnd(); //Only run this at the end
}
For a quick and dirty namespace solution, internal global variables and functions start with "_", and user functions start with "t" (for test).
This starts a new set of tests, and resets some internal counters. This also ends the previous set of tests, if there was one.
Code:
tTest("my function is awesome");
Output:
# my function is awesome
This checks if test
is true
.
Code:
tOk(bLcdBacklight, "the backlight is on");
Output:
ok 1 the backlight is on
This checks if test
is false
.
Code:
tNotOk(bLcdBacklight, "the backlight is off");
Output:
ok 2 the backlight is off
This checks if test
equals expected
.
Code:
tEqual(motor[MY_MOTOR], 127, "MY_MOTOR is running full speed.");
Output:
ok 3 MY_MOTOR is running full speed.
This checks if test
does not equal unexpected
.
Code:
tNotEqual(motor[MY_MOTOR2], 0, "MY_MOTOR is not still");
Output:
ok 4 MY_MOTOR2 is not still
This is a test that always passes.
Code:
tPass("yay this works")
Output:
ok 5 yay this works
This is a test that always fails.
Code:
tFail("that was predictable")
Output:
not ok 6 that was predictable
---
got: 0
expected: 1
...
This ends the last set of tests. Use tTest()
to end any set that isn't last.