Skip to content

Testing

Marek Milkovič edited this page Oct 21, 2013 · 5 revisions

Test Suite

Test suite is group of test cases which aim is to test one specific group or module of your program. Whenever you want to make new test suite, create file that has prefix test to include it into testing build. The best naming would be test_NAME_OF_MODULE.c (e.g.: test_scanner.c or test_string.c).

Structure of your file will be like this

#include "test.h"

TEST_SUITE_START(NameOfTestSuite) // e.g. TEST_SUITE_START(StringTests)

// test cases

TEST_SUITE_END

To make your new test suite run with our testing build, you need to register it. Open test.c and add TEST_SUITE(NameOfTestSuite) before main function and REGISTER_TEST_SUITE(NameOfTestSuite) before RUN_TEST_SUITES.

Test Case

Test case is test of one specific part of test suite. These macros are available for you for testing

SHOULD_BE_TRUE(TestCaseName, expr) // Passes when "expr" is true
SHOULD_BE_FALSE(TestCaseName, expr) // Passes when "expr" is false
SHOULD_EQUAL(TestCaseName, val1, val2) // Passes when val1 == val2
SHOULD_NOT_EQUAL(TestCaseName, val1, val2) // Passes when val1 != val2
SHOULD_BE_GRT(TestCaseName, val1, val2) // Passes when val1 > val2
SHOULD_BE_GRT_EQ(TestCaseName, val1, val2) // Passes when val1 >= val2
SHOULD_BE_LESS(TestCaseName, val1, val2) // Passes when val1 < val2
SHOULD_BE_LESS_EQ(TestCaseName, val1, val2) // Passes when val1 <= val2
SHOULD_EQUAL_STR(TestCaseName, str1, str2) // Passes when strcmp(str1, str2) == 0
SHOULD_NOT_EQUAL_STR(TestCaseName, str1, str2) // Passes when strcmp(str1, str2) != 0

TestCaseName is the name shown in the output of the test. Should describe the test so we know what is being tested just from name.

Running tests

Just run make test a start ini-test

Reporting tests

If you found any of the tests you wrote failing, run ./ini-test -f and create new issue with Blocker priority and as Bug with the log from the test run.

Clone this wiki locally