The cppunit.textui TestRunner is a command line tool provided by the CppUnit package library for running unit test cases written in C++. It provides a simple and intuitive way to execute tests and view the results.
Example 1: Here is a simple example demonstrating how to use the TestRunner to run a test suite.
#include #include
#include "MyTest.h"
int main() { // Create the test suite and add tests CppUnit::TestSuite* testSuite = new CppUnit::TestSuite(); testSuite->addTest(new MyTest());
// Run tests using the TestRunner CppUnit::TextUi::TestRunner runner; runner.addTest(testSuite); runner.run();
delete testSuite; return 0; }
In this example, we first create a test suite and add a test case to it. We then use the TestRunner to run the tests in the suite.
Example 2: Here is another example demonstrating how to configure the TestRunner to produce different output formats.
#include #include #include #include
#include "MyTest.h"
int main() { // Create the test suite and add tests CppUnit::TestSuite* testSuite = new CppUnit::TestSuite(); testSuite->addTest(new MyTest());
// Create the TestRunner and set output format CppUnit::TextUi::TestRunner runner; runner.setOutputter(new CppUnit::CompilerOutputter(&runner.result(), std::cerr)); runner.addTest(testSuite);
// Configure test listener for progress and result collection CppUnit::TestResult result; CppUnit::TestResultCollector collector; result.addListener(&collector); CppUnit::BriefTestProgressListener progress; result.addListener(&progress);
// Run tests and output results runner.run(result); std::cout << collector.getResult() << std::endl;
delete testSuite; return 0; }
In this example, we create the TestRunner and set a different output format using the CompilerOutputter. We also configure a TestResult and TestResultCollector to collect the test results, and a BriefTestProgressListener to display progress information during test execution.
Package library: CppUnit.
C++ (Cpp) TestRunner - 30 examples found. These are the top rated real world C++ (Cpp) examples of cppunit::textui::TestRunner extracted from open source projects. You can rate examples to help us improve the quality of examples.