You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Minimal unit testing framework for personal and small scale C++ projects.
Mini-Test has a familiar interface emulating GoogleTest framework. When it's time to move on to a more
robust testing framework such as GoogleTest, only minimal refactoring is required.
Minitest is easy to use. There are no dependencies except the C++ standard library.
The library can be consumed as a CMake project or header only.
Initially created as a quick replacement for GoogleTest. Suprisingly, it has served me well in the pass 2
years developing and testing my personal projects. So, I have decided to continue improving this library
rather than abandoning it for GoogleTest.
Example of a unit test:
auto my_method() { return true; }
TEST(MyTest,MyTestCase){
EXPECT_TRUE(my_method());
EXPECT_TRUE_LOG(false,"error!"+my_method()); // All checks and asserts have a log// version recieving a string.EXPECT_FALSE(false);
EXPECT_EQ(1,1);
EXPECT_NE(1,2);
EXPECT_ANY_THROW([](){ throwstd::runtime_error("error"); });
EXPECT_NO_THROW([](){ throwstd::runtime_error("error"); });
throw"oops"!; // Unexpected exceptions will be caught and reported.
}
Example of a fixture unit test:
structMyFixture : minitest::Fixture {
intmy_foo=0;
voidSetUp() override {
std::cout << "Setting up the fixture\n";
}
voidTearDown() override {
std::cout << "Tearing down the fixture\n";
}
};
MINITEST_F(MyFixtureTest, MyFixtureTestCase, MyFixture) {
EXPECT_TRUE(my_foo==0);
}
Example of retrieving the test result/accessing result later at runtime:
FINISH_MINITESTS; // Macro to finish the test suite, call before main function.// Main Function is unaffected by the unit tests.intmain() {
std::cout << "Hello World!\n";
if (MINITESTS_RESULT)
std::cout << "Testing was successful.\n";
elsestd::cout << "A test case failed.\n";
returnMINITESTS_RESULT ? 0 : 1; // example of return result based on tests.
}