cppunitユニットテスト
1217 ワード
#include
#include "cppunit/ui/text/TestRunner.h"
#include "cppunit/TestCaller.h"
#include "cppunit/TestSuite.h"
#include "cppunit/extensions/HelperMacros.h"
#include "cppunit/TestAssert.h"
using namespace std;
class MathTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(MathTest);
CPPUNIT_TEST(testAdd);
CPPUNIT_TEST(testDec);
CPPUNIT_TEST_SUITE_END();
protected:
int m_value1,m_value2;
public:
MathTest(){}
~MathTest(){}
//chushihua
void setUp()
{
m_value1 = 2;
m_value2 = 3;
}
void testAdd()
{
int result = m_value1 + m_value2;
CPPUNIT_ASSERT(result == 5);
CPPUNIT_ASSERT_MESSAGE("ERROR Message",result == 5);
}
void testDec()
{
int result = m_value2 - m_value1;
CPPUNIT_ASSERT(result == 1);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(MathTest);
int main(int argc,char* argv[])
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest(registry.makeTest());
runner.run();
return 0;
}