Temper

Click here to access the GitHub repo.

Temper is a single header unit testing framework for C/C++. It supports the following features:

I initially wrote Temper because I wasn’t happy with pre-existing options. GTest was a nightmare to integrate into a project and Greatest looked OK but had some friction between the public/private API. All the others I found were just weird and did not have great usability in my opinion.

I decided that I knew what I wanted from a unit-testing framework so I decided to sit down one weekend and just write one. That was V1.

For V2 I collaborated with a friend of mine to implement all the features listed above. The library is much better as a result.

Writing tests for Temper is incredibly simple:

#define TEMPER_IMPLEMENTATION
#include <temper/temper.h>

TEMPER_TEST( Test_FloatsAreEqual, TEMPER_FLAG_SHOULD_RUN ) {
	TEMPER_CHECK_FLOAT_EQUAL( 0.0f, 0.000001f );
}

int main( int argc, char** argv ) {
	TEMPER_RUN( argc, argv );

	return 0;
}

Tests are self registering (even in the C API) so all you have to do is write the test and Temper will run it.

Parametric tests are technically not self registering but that’s only because you need to invoke them once for each set of parameters that you want to give the test:

#define TEMPER_IMPLEMENTATION
#include <temper/temper.h>

TEMPER_PARAMETRIC( Test_FloatsAreEqual, TEMPER_FLAG_SHOULD_RUN, const float a, const float b ) {
	TEMPER_CHECK_FLOAT_EQUAL( a, b );
}

TEMPER_INVOKE_PARAMETRIC_TEST( Test_FloatsAreEqual, 0.0f, 0.000001f );
TEMPER_INVOKE_PARAMETRIC_TEST( Test_FloatsAreEqual, 0.0f, 1.234567f );

int main( int argc, char** argv ) {
	TEMPER_RUN( argc, argv );

	return 0;
}