CppUTest
CppUTest

CppUTest unit testing and mocking framework for C/C++

More information on the project page

![Build Status](https://travis-ci.org/cpputest/cpputest.png?branch=master)

Getting Started

You'll need to do the following to get started:

Building from source (unix-based, cygwin, MacOSX):

You can also use CMake, which also works for Windows Visual Studio.

Then to get started, you'll need to do the following:

After this, you can write your first test:

```C++ TEST_GROUP(FirstTestGroup) { };

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

Command line switches

Test Macros

Set up and tear down support

Assertion Macros

The failure of one of these macros causes the current test to immediately exit

Customize CHECK_EQUAL to work with your types that support operator==()

The Extensions directory has a few of these.

Building default checks with TestPlugin

Example of a main with a TestPlugin:

```C++ int main(int ac, char** av) { LogPlugin logPlugin; TestRegistry::getCurrentRegistry()->installPlugin(&logPlugin); int result = CommandLineTestRunner::RunAllTests(ac, av); TestRegistry::getCurrentRegistry()->resetPlugins(); return result; } ```

Memory leak detection

How is memory leak detection implemented?

If you use some leaky code that you can't or won't fix you can tell a TEST to ignore a certain number of leaks as in this example:

```C++ TEST(MemoryLeakWarningTest, Ignore1) { EXPECT_N_LEAKS(1); char* arrayToLeak1 = new char[100]; } ```

Example Main

```C++ #include "UnitTestHarness/CommandLineTestRunner.h"

int main(int ac, char** av) { return CommandLineTestRunner::RunAllTests(ac, av); }

IMPORT_TEST_GROUP(ClassName) ```

Example Test

```C++ #include "UnitTestHarness/TestHarness.h" #include "ClassName.h"

TEST_GROUP(ClassName) { ClassName* className;

void setup() { className = new ClassName(); } void teardown() { delete className; } }

TEST(ClassName, Create) { CHECK(0 != className); CHECK(true); CHECK_EQUALS(1,1); LONGS_EQUAL(1,1); DOUBLES_EQUAL(1.000, 1.001, .01); STRCMP_EQUAL("hello", "hello"); FAIL("The prior tests pass, but this one doesn't"); } ```

There are some scripts that are helpful in creating your initial h, cpp, and Test files. See scripts/README.TXT