In order to let testing enough simple, this is a very small header file in C/C++ template recursive and variadic.
Only one assertion template, zero learning time.
You just write a test unit, no matter where, and the compiler does the rest for you.
It is designed to let users focus on writing test scenarios. Each test unit is a native struct or class, so there are no "weird" test fixtures. The only assertion tool is normal method, so avoids using macros in a unit test.
- Only a header file, only use C++ compiler.
- Any member method or function can be tested.
- No concept to learn, no heavy documentation, just one assertion tool.
- No config, no test macro, no graphic interface, no extrernal library.
- Can run a test unit or suite by wild card pattern.
- Extended easily and integrated easily into an application.
template <class A>
static void _assert(const A& expression, const char* shouldbe=0, ...);
The below code snippet demonstrates the least amount of code required to write an executable test:
/* 1.Add this header file into your project */
#include "CppUnitTestExpress.h"
/* 2. Write a test unit given a name. */
class TestMinimal : public Unit<TestMinimal>
{
void Test()
{
_assert(true,"Should be true.");
}
};
/* Only this test is executed. */
class TestMinimal : public Unit<TestMinimal>::Only
{
void Test()
{
_assert(true,"Should be true.");
}
};
/* Skip this test. */
class TestMinimal : public Unit<TestMinimal>::Skip
{
void Test()
{
_assert(true,"Should be true.");
}
};
/* 3. Run the unit test. */
int main(int argc, char* argv[])
{
return 0;
}
/* The result of test is displayed. */
SUCCESS : TestMinimal - 0s
----------------------------------------
Executed: 1 unit, 0s at 2025-01-12 20:30:47
Resulted: SUCCESS