?????????????д???MyTest?????test1??????в??????test1.runTest()?????н?????????????????????
???????????????????????????????????????????????? TestCase????????TestFixture??TestFixture?????TestSuite?????TestSuite???????ж??TestCase?????????2?????????
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/ui/text/TestRunner.h>
class MyTests : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( MyTests );
CPPUNIT_TEST( testAdd );
CPPUNIT_TEST( testEquals );
CPPUNIT_TEST_SUITE_END();
double m_value1;
double m_value2;
public:
void setUp()
{
m_value1 = 2.0;
m_value2 = 3.0;
}
void tearDown()
{
}
void testAdd()
{
double result = m_value1 + m_value2;
CPPUNIT_ASSERT( result == 6.0 );
}
void testEquals()
{
long* l1 = new long(12);
long* l2 = new long(12);
CPPUNIT_ASSERT_EQUAL( 12?? 12 );
CPPUNIT_ASSERT_EQUAL( 12L?? 12L );
CPPUNIT_ASSERT_EQUAL( *l1?? *l2 );
delete l1;
delete l2;
CPPUNIT_ASSERT( 12L == 12L );
CPPUNIT_ASSERT_EQUAL( 12?? 13 );
CPPUNIT_ASSERT_DOUBLES_EQUAL( 12.0?? 11.99?? 0.5 );
}
};
int main()
{
CppUnit::TextUi::TestRunner runner;
runner.addTest( MyTests::suite() );
runner.run();
return 0;
}
????????????????????????????MyTests??????в????????o?
????CPPUNIT_TEST_SUITE( MyTests );
????CPPUNIT_TEST( testAdd );
????CPPUNIT_TEST( testEquals );
????CPPUNIT_TEST_SUITE_END();
?????????????????????TestCase: testAdd??testEquals????????????TestCase?????????MyTests??TestSuite?????
????????????????????????TestRunner?????runner????MyTests???????????????????runner????????runner.run()?????????е???????????
??????????????У????????????????????????Щ?????????ξ??????????????????仯?????????????????????????????????????????????e?????????仯???????Ч?????????????????????У?TestRunner???????????????????????????????????????????????????????????????????????????CPPUNIT????????????????????TestRunner?????????????????????????????????????????????????????????????????????????????????ò??????????????TestRunner??TestRunner????????????????????run()????????????????????????????????????????????е????д???
????CppUnit::TextUi::TestRunner runner;
????runner.addTest( MyTests::suite() );
????runner.run();
??????1?к??3?ж?????????????????????仯???仯????????2???У??????????????????????????TestRunner??
??????????????????????????????????????????д?μ???鰱?????????????????????????????????仯????????????KDL???????????????????
????framestest.hpp??framestest.cpp??????????????????????????????????????????KDL??frames??飬???????????????
????CPPUNIT_ASSERT_DOUBLES_EQUAL((R*v).Norm()??v.Norm()??epsilon);
???????????????????v???????????R??????????????????????????????????????????????о?????????????epsilon?????????????????epsilon??Χ???
????????????????????2?????????????????в????????framestest.cpp?????????????д???
????CPPUNIT_TEST_SUITE_REGISTRATION( FramesTest );
??????KDL??tests???У??ж????FramesTest????????????????????????????JacobianTest??????cpp?????????????д???
????CPPUNIT_TEST_SUITE_REGISTRATION(JacobianTest);
????test-runner.cpp???????????????
#include <cppunit/XmlOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <iostream>
#include <fstream>
int main(int argc?? char** argv)
{
// Get the top level suite from the registry
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
// Adds the test to the list of test to run
CppUnit::TextUi::TestRunner runner;
runner.addTest( suite );
#ifndef TESTNAME
std::ofstream outputFile(std::string(suite->getName()+"-result.xml").c_str());
#else
std::ofstream outputFile((std::string(TESTNAME)+std::string("-result.xml")).c_str());
#endif
// Change the default outputter to a compiler error format outputter
runner.setOutputter( new CppUnit::XmlOutputter( &runner.result()??outputFile ) );
// Run the tests.
bool wasSucessful = runner.run();
outputFile.close();
// Return error code 1 if the one of test failed.
return wasSucessful ? 0 : 1;
}
?????????????м??д???????????????log??????????????????????????д???
????runner.addTest( suite );
????bool wasSucessful = runner.run();
???????2???????????????????????????2???????У???????????????TestSuite??????runner?У???????????????У????????д?????????KDL???е???????????????suite?У?
????CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
???????????????е???????????????????????????????CPPUNIT_TEST_SUITE_REGISTRATION???????????????????????????????????????????????????е????????????????????????????У?test-runner.cpp???????????????????????????????仯???д?????????????????в?????????????棬???????????????????????????