CppUnit is a C++ unit testing framework library that allows developers to write and execute automated tests in a structured and organized manner. One of the most commonly used features of this library is the TestRunner class, which provides an all-in-one solution for running and reporting tests.
The TestRunner class in the cppunit.textui package can be used to search for and execute test cases that are registered with a CppUnit::TestSuite object. It takes care of initializing the framework, executing the selected tests, and presenting the results in a readable format.
Here are some sample code examples of using TestRunner in C++:
Example 1:
#include #include "my_test_cases.h" // assume this header file contains all test cases
In this example, we include the TestRunner header file and a header file containing our test cases. We create a TestRunner object and add all available tests to it. Finally, we execute the tests and return the appropriate exit code depending on whether all tests pass or some fail.
Example 2:
#include #include
class MyTestCase : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(MyTestCase); CPPUNIT_TEST(my_test); CPPUNIT_TEST_SUITE_END();
int main() { CppUnit::TextUi::TestRunner runner; runner.addTest( new CppUnit::TestCaller("my_test", &MyTestCase::my_test) ); return runner.run() ? 0 : 1; }
In this example, we define a simple test case for checking the correctness of an addition operation. We use the CppUnit macros to define the test case and add a single test to it. We then create a TestCaller object to register the test with the TestRunner. Finally, we execute the test and return the appropriate exit code.
Overall, the TestRunner class is a useful tool for automatically running and reporting results of unit tests in C++. It is part of the cppunit.textui package in the CppUnit library.
C++ (Cpp) TestRunner::addTest - 30 examples found. These are the top rated real world C++ (Cpp) examples of cppunit::textui::TestRunner::addTest extracted from open source projects. You can rate examples to help us improve the quality of examples.