#include#include #include "TestExample.h" int main() { CPPUNIT_NS::TestSuite suite; suite.addTest( new TestExample() ); CPPUNIT_NS::TextUi::TestRunner runner; runner.addTestSuite( &suite ); runner.run(); return 0; }
#includeThis example creates a custom test class `MyTestClass` which inherits from `CppUnit::TestFixture`. It also creates a test method `testMethod` inside the class, which creates an instance of `MyClass` and calls its `myMethod`, and asserts that the result is `true`. The test method is added to a `TestCaller` object, which is then executed using the `TestRunner`. The `TestRunner` displays the results on the console. These examples use the `cppunit.textui` package library, which is a part of the CppUnit library for C++. The `cppunit.textui` package provides a command-line interface for running tests and displaying the results in different formats.#include #include #include "MyClass.h" class MyTestClass : public CppUnit::TestFixture { public: void testMethod() { MyClass obj; CPPUNIT_ASSERT_EQUAL( true, obj.myMethod() ); } }; int main() { CppUnit::TestResult result; CppUnit::TestCaller test( "testMethod", &MyTestClass::testMethod ); test.run( &result ); CppUnit::TextUi::TestRunner runner; runner.addTest( &test ); runner.run(); return 0; }