??дCppUnit????????
???????????? ???????[ 2013/10/12 17:12:05 ] ????????
???????????????????
????1????Fixture???????????????????????????????????????CppUnit::TestCaller?????
??????????????????Fixture????????????????????Fixture??CppUnit?а??????????е??????????????TestSuite??
??????TestRunner?????в???????????TestSuite????????????в??????????????????????????3??TestRunner:
????(1) CppUnit::TestUi::TestRunner//????????TestRunner
????(2) CppUnit::QtUi:: TestRunner//Qt?????TestRunner
????(3) CppUnit::MfcUi:: TestRunner//MFC???
???????????????
????1???????????????????
????2?????????????????
????3??????GUI??????MFC???????
???????????????
????1????????????????
????????? cppunitd_dll.dll??cppunitd_dll.lib??
???????????????????????TestRunner ?磺CppUnit::TestUi::TestRunner??
????Step1:????????????????д??????????????CppUnit::TestFixture??????????2???麯????void setup()??void teardown();
????void setup() ?????????????
????void teardown() ?????β???????????
???????????????2????????
????Step2:??д???????????????testAdd();
????Step3:??д?????????????
??????????????£?
main.cpp
#include "MathTest.h"
#include "cppunit/TestSuite.h"
#include "cppunit/ui/text/TestRunner.h"
#include "cppunit/TestCaller.h"
#include <iostream>
using namespace std;
#pragma comment (lib?? "cppunitd_dll.lib")
int main()
{
CppUnit::TextUi::TestRunnerrunner;
CppUnit::TestSuite*suite = new CppUnit::TestSuite();
//??????????????
suite->addTest(newCppUnit::TestCaller<MathTest>("testAdd"??&MathTest::testAdd));
//???????TestSuite
runner.addTest(suite);
//??????У????????????????????
runner.run(""??true);
return 0;
}
MathTest.h
#include "cppunit/TestFixture.h"
class MathTest:public CppUnit::TestFixture
{
public:
//?????????
void setUp();
//???????
voidtearDown();
//??????????????
voidtestAdd();
protected:
intm_value1??m_value2;
};
MathTest.cpp
#define MATHTEST_H
#ifdef MATHTEST_H
#include "MathTest.h"
#include "cppunit/TestAssert.h"
#endif
void MathTest::setUp()
{
m_value1 = 2;
m_value2 = 3;
}
void MathTest::tearDown()
{
}
void MathTest::testAdd()
{
int ret =m_value1 + m_value2;
CPPUNIT_ASSERT(ret== 5);
}
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11