I’ve never understood why people use GTest, CppUnit, Catch, oh wait, Catch2 now.
Here is my C++ unit test framework:
// test object constructor calls function struct test { test(const std::function& f) { try { f(); } catch (const std::exception& ex) { fputs(ex.what(), stderr); } } };
Just write a int main() { return 0; }
file and add .cpp
files that call your tests.
They look something like this:
test my_function([]() { assert (my_function_works()); });
Just make sure my_function_works
throws an exception with an informative message. I use ensure
for that.
More examples can be found here.
Why make things complicated?