February 18, 2013

UnitTest++

Writing unit tests for your C++ code is sometimes painful. But fear no more, with UnitTest++ and it's fixture feature, your shared data between the individual tests becomes so easy to set up it's almost cheating! Sweet!


The code in the tweet is for the svn version of the unittest++ framework, not the one available in google code!!

Just dump the files in your test directory and use them like this:

#include <fstream>
#include <unittest++/UnitTest++.h>
#include <unittest++/TestRunner.h>
#include <test_reporter_junit.h>

using namespace std;
using namespace UnitTest;

int main()
{
    ofstream f("test-report.xml");
    Test_reporter_junit reporter(f);
    TestRunner runner(reporter);
    return runner.RunTestsIf(Test::GetTestList(),NULL,True(),0);
}

 

No comments: