Turns out that Registration for the test case is missing. Therefore, the following line is needed in the testclassname.cpp
CPPUNIT_TEST_SUITE_REGISTRATION (testclassname);
문제
I'm currently doing cppunit testing on my project. The 2 functions checkWord and checkFile both return 'true' bool values when I compile and run the program normally. Then when I use these 2 functions for my cppunit testing. The output result will always be OK(0). Instead of the OK(1) I should be seeing when i run either of the CPPUNIT_ASSERT(). Anyone can help me with this?
Below are my codes for the project:
checkWord function
bool ScrambleWordGame::checkWord(string checkWord) {
ifstream file("WordDatabase.txt");
vector <string> wordList;
copy(istream_iterator<string>(file),
istream_iterator<string>(),
back_inserter(wordList));
file.close();
if(find(wordList.begin(),wordList.end(),checkWord) != wordList.end())
return true;
else
return false;
}
checkFile function
bool ScrambleWordGame::checkFile(string filename) {
ifstream file(filename.c_str());
if(file)
return true;
else
return false;
file.close();
}
SWGTest.cpp
#include "ScrambleWordGameTest.h"
#include "ScrambleWordGame.h"
void ScrambleWordGameTest::testEquals() {
CPPUNIT_ASSERT(swg.checkFile("WordDatabase.dat"));
//CPPUNIT_ASSERT(swg.checkWord("cat"));
}
해결책
Turns out that Registration for the test case is missing. Therefore, the following line is needed in the testclassname.cpp
CPPUNIT_TEST_SUITE_REGISTRATION (testclassname);