Youngman's very simple test-framework
-
global test cases
#include "ytest.h" // lambda function YTEST_CASE("A", []() { // The name of this test case is "A" cout << "TEST A" << endl; return true; // no error }); // C-style function bool testB() { cout << "TEST B" << endl; return true; // no error } YTEST_CASE("B", testB); // The name of this test case is "B" // Function object struct TestC { bool operator()() const { cout << "TEST C" << endl; return true; } }; YTEST_CASE("C", TestC()); // The name of this test case is "C"
-
C++ test suites
#include "ytest.h" class Tester : public ytest::TestSuite { public: static void setUpTestSuite() { cout << "Tester::setUpTestSuite()" << endl; } static void tearDownTestSuite() { cout << "Tester::tearDownTestSuite()" << endl; } virtual void setUp() override { cout << "Tester::setUp()" << endl; } virtual void tearDown() override { cout << "Tester::tearDown()" << endl; } }; YTEST_F(Tester, case_name_1) { cout << "test Test.case_name_1 ..." << endl; } YTEST_F(Tester, case_name_2) { cout << "test Test.case_name_2 ..." << endl; YEXPECT_TRUE(!3 != 0); YEXPECT_FALSE(!3 == 0); YEXPECT_EQ(!3, true); YEXPECT_NE(!3, false); }
-
The following code can also be added to the main() function.
#include "ytest.h" int main(int argc, char* argv[]) { //... return ytest::runTestCases(argc, argv); }
-
run all test cases
$ <your-executable-file> -
run specific test cases: a test case "A", a test case "B" and a test case "C"
# <your-executable-file> A B Cor
# <your-executable-file> A,B,Cor
# <your-executable-file> A,B C -
run specific test cases: all test cases to begin with "A" and a test case "C"
# <your-executable-file> A*,Cor
# <your-executable-file> A* C