The unit test harness supplied with CppTestTools is based on Michael Feathers CppUnitLite.

CppTestTools.UnitTestHarness supports these features

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

Memory leak detection


Example Main

#include "UnitTestHarness/CommandLineTestRunner.h"

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

IMPORT_TEST_GROUP(ClassName)

Example Test

#include "UnitTestHarness/TestHarness.h"
#include "ClassName.h"

EXPORT_TEST_GROUP(ClassName)

namespace 
{
  ClassName* aClassName;

  void SetUp()
  {
    aClassName = new ClassName();
  }
  void TearDown()
  {
    delete aClassName;
  }
}

TEST(ClassName, Create)
{
  CHECK(true);
  CHECK_EQUALS(1,1);
  LONGS_EQUAL(1,1);
  DOUBLES_EQUAL(1.000, 1.001, .01);
  STRCMP_EQUAL("hello", "hello");
  FAIL("Making sure ClassNameTest is hooked in");
}

SetUp and TearDown are located within the unnamed namespace. This avoids global name pollution as SetUp and TearDown will only be visable within the current file.