A small, header-only C++ unit testing library. With TinyCppTest you can set up your test environment in a couple of minutes. You only have to include one header file in your project, init the library in the main function, and start testing.
Download the Sources/TinyCppTest.hpp file, and add it to your project.
Just call RunTests
in your main function. It will return true if every tests are successful, false otherwise.
#include "TinyCppTest.hpp"
int main (int, char*[])
{
if (!TinyCppTest::RunTests ()) {
return 1;
}
return 0;
}
You can write tests in any C++ files using the TEST
macro. Use the ASSERT
macro to check conditions.
#include "TinyCppTest.hpp"
TEST (AdditionTest)
{
ASSERT (40 + 2 == 42);
}
TEST (SubtractionTest)
{
ASSERT (44 - 2 == 42);
}
You can use the assertion types below:
ASSERT (condition)
: Checks if the given condition is true.ASSERT_EQ (a, b)
: Checks if the given values are equal using the equality operator.ASSERT_NEQ (a, b)
: Checks if the given values are not equal using the inequality operator.ASSERT_EQ_EPS (a, b, eps)
: Checks if the given numbers are equal using the given epsilon.ASSERT_NEQ_EPS (a, b, eps)
: Checks if the given numbers are not equal using the given epsilon.
Run the created executable file, and check the results in the console.