YourFirstTest

Documentation

This file is available as simple.c, and can be built by typing "make" in the extracted directory. More information about how to use the framework is available in HowToUse, and a list of assertion macros is available in MacroReference.

#include "tests.h"

// Start the overall test suite
START_TESTS()

// A new group of tests, with an identifier
START_TEST("simple")
// We then write the tests we want to check
ASSERT(1 == 1);
ASSERT_EQUALS_FLOAT(1, 1);
END_TEST()

START_TEST("fail")
// These tests will fail, and we will get output.
ASSERT(1 == 0);
ASSERT_EQUALS_FLOAT(1, 0);

// Lets give a description of the test, before it
// fails - this will be printed out instead.
TEST("we expect this test to fail. (3==2)");
ASSERT(3 == 2);
END_TEST()

// End the overall test suite
END_TESTS()

Once you've got this test written, save it as "simple.c", compile and link it, and run it. You can also do this by going typing in make. It will execute all the tests and display the output to the console:

$ ./simple
> simple...
> fail...
[FAIL?] simple.c:21 : (fail) : 1 == 0 fails
[FAIL?] simple.c:22 : (fail) : 1 is supposed to equal (float) 0
(0.000000 != 1.000000)
[FAIL?] simple.c:26 : (fail) : we expect this test to fail. (3==2)

--- Results ---
Tests run: 2
Passes: 2
Failures: 3

A full list of all the macros available are in the MacroReference section.

Powered by Wiki! and
SourceForge.net Logo