Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
You are viewing an older revision! See the latest version
Homepage
CppUTest¶
Where to find more information¶
- The CppUTest manual can be found at www.cpputest.org
- If you have any question, check out the https:groups.google.com/forum/?fromgroups#!forum/cpputest
- The sources from which this library was derived may be found at the https:github.com/cpputest/cpputest
Quick introduction (some code!)¶
To write your first test, all you need is a new cpp file with a TEST_GROUP and a TEST, like:
<<code> TEST_GROUP(FirstTestGroup) { };
TEST(FirstTestGroup, FirstTest) { FAIL("Fail me!"); } <</code>>
This test will fail.
You can add new tests to the test group by just writing more tests in the file, like this:
TEST(FirstTestGroup, SecondTest)
{
STRCMP_EQUAL("hello", "world");
LONGS_EQUAL(1, 2);
CHECK(false);
}
You do need to trigger the tests from somewhere in your program. It could look something like:
int main(int ac, char** av)
{
...
CommandLineTestRunner::RunAllTests(0 /* ac */, (const char **)NULL /* av */);
...
}
For more information, We’d recommend to http:www.cpputest.org/ or, even better, check some https:github.com/cpputest/cpputest/tree/master/tests such as https:github.com/cpputest/cpputest/blob/master/tests/SimpleStringTest.cpp or (a bit more complicated) https:github.com/cpputest/cpputest/blob/master/tests/MemoryLeakDetectorTest.cpp or the mocking tests or just check out the https:github.com/cpputest/cpputest/blob/master/tests/CheatSheetTest.cpp.