Unit Testing framework based on http://cpputest.github.io/

CppUTest

Where to find more information

Getting test reports on the console

You may need to tailor the file src/Platforms/mbed/UtestPlatform.cpp to your needs. In particular, if you want console output, you might want to look at the function PlatformSpecificPutchar().

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:

#include "CppUTest/TestHarness.h"

TEST_GROUP(FirstTestGroup)
{
};

TEST(FirstTestGroup, FirstTest)
{
   FAIL("Fail me!");
}

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:

#include "CppUTest/TestRegistry.h"
#include "CppUTest/CommandLineTestRunner.h"

int main(int ac, char** av)
{
    ....
    unsigned failureCount = 0;
    {
        ConsoleTestOutput output;
        CommandLineTestRunner runner(ac, av, &output, TestRegistry::getCurrentRegistry());
        failureCount = runner.runAllTestsMain();
    }

    if (failureCount == 0) {
        console.printf("PASSED\r\n");
    }
    ...
}

For more information, We’d recommend to read the manual or, even better, check some existing tests such as SimpleStringTest or (a bit more complicated) MemoryLeakDetectorTest or the mocking tests or just check out the Cheat Sheet.

Revision:
1:4769360130ed
Parent:
0:0b799af9d58e
--- a/include/CppUTest/SimpleString.h	Tue Jan 28 09:27:41 2014 +0000
+++ b/include/CppUTest/SimpleString.h	Tue Jun 17 15:52:54 2014 +0100
@@ -90,13 +90,15 @@
 	static void setStringAllocator(TestMemoryAllocator* allocator);
 
 	static char* allocStringBuffer(size_t size);
+	static char* StrNCpy(char* s1, const char* s2, size_t n);
 	static void deallocStringBuffer(char* str);
 private:
 	char *buffer_;
 
 	static TestMemoryAllocator* stringAllocator_;
 
-	char* getEmptyString() const;
+	char* getEmptyString() const; 
+	static char* copyToNewBuffer(const char* bufferToCopy, size_t bufferSize=0);
 };
 
 class SimpleStringCollection
@@ -124,15 +126,17 @@
 SimpleString StringFrom(char value);
 SimpleString StringFrom(const char *value);
 SimpleString StringFromOrNull(const char * value);
+SimpleString StringFrom(int value);
+SimpleString StringFrom(unsigned int value);
 SimpleString StringFrom(long value);
-SimpleString StringFrom(int value);
+SimpleString StringFrom(unsigned long value);
 SimpleString HexStringFrom(long value);
+SimpleString HexStringFrom(unsigned long value);
 SimpleString HexStringFrom(const void* value);
 SimpleString StringFrom(double value, int precision = 6);
 SimpleString StringFrom(const SimpleString& other);
 SimpleString StringFromFormat(const char* format, ...) __check_format__(printf, 1, 2);
 SimpleString VStringFromFormat(const char* format, va_list args);
-SimpleString StringFrom(unsigned int value);
 
 #if CPPUTEST_USE_STD_CPP_LIB
 
@@ -140,7 +144,6 @@
 #include <stdint.h>
 
 SimpleString StringFrom(const std::string& other);
-SimpleString StringFrom(unsigned long);
 
 #endif