With some small changes your code should work.
// ParserUnitTests.h
#include <cppunit\TestFixture.h>;
#include <cppunit\extensions\HelperMacros.h>
class ParserUnitTests : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ParserUnitTest);
CPPUNIT_TEST(testCanDoUnitTest);
CPPUNIT_TEST_SUITE_END();
public:
void testCanDoUnitTest();
};
CPPUNIT_TEST_SUITE_REGISTRATION( ParserUnitTest );
and
// ParserUnitTests.cpp
#include "ParserUnitTests.h"
void ParserUnitTests::testCanDoUnitTest() {
CPPUNIT_ASSERT_EQUAL(1, 2, "Expected failure");
}
then you only need a main (which I copied just from the Cppunit cookbook)
// main.cpp
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main()
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest( registry.makeTest() );
bool wasSuccessful = runner.run();
return !wasSuccessful;
}
So the only change is that you need to declare the test suite in the header file inside the TestFixture declaration.