Click here to Skip to main content
15,893,588 members
Articles / Desktop Programming / MFC

Unit Test's Reporter

Rate me:
Please Sign up or sign in to vote.
4.86/5 (28 votes)
19 Feb 2006CPOL11 min read 64.8K   2.8K   58  
The article describes an application built to visualise testing processes for the unit test framework of CppUnitLite.
#include "TestResult.h"
#include "Failure.h"
#include "Success.h"
#include <stdio.h>
#include "TVTInterface.h"

#ifndef	null
#define	null	0
#endif

#define	APPL_ID	TEXT("TestApp")

TestResult::TestResult()
	:	failureCount_	(0),
		allCheckCount_	(0),
		successCount_	(0),
		debug_		(false),
		statistics_	(false),
		trace_		(false)
{
}

TestResult::TestResult(
	const bool debugMode, const bool statMode, const bool traceMode)
	:	failureCount_	(0),
		allCheckCount_	(0),
		successCount_	(0),
		debug_	(debugMode),
	statistics_	(statMode),
		trace_	(traceMode)
{
}

void TestResult::TestsStarted () 
{
}

//	The test  is executed successfully
void TestResult::AddSuccess (const Success& success) 
{
	if (debug_ == false
	)	return
	;
	fprintf (stdout, "Test(%s,%s)\t[%s]\tis executed successfully: ",
		success.testName_,success.testGroup_,success.testMacro_);
	fprintf (stdout, "%s%s%s%s%ld%s%s\n",
		"\"",
		success.message_.AsCharString (),
		"\" " ,
		"line ",
		success.lineNumber_,
		" in ",
		success.fileName_.AsCharString ());

}

void TestResult::AddFailure (const Failure& failure) 
{
	fprintf (stdout, "[!] Test(%s,%s) is failed: ",failure.testName_,failure.testGroup_);
	fprintf (stdout, "%s%s%s%s%ld%s%s\n",
		"\"",
		failure.message_.AsCharString (),
		"\" " ,
		"line ",
		failure.lineNumber_,
		" in ",
		failure.fileName_.AsCharString ());
		
	failureCount_++;

//////////////////////////////////////////////////////////////////////////////
	TVTSendTestFailure(
		failure.testName_	.AsCharString(),
		failure.testGroup_	.AsCharString(),
		failure.errorReason_.AsCharString(),
		failure.messageXML_	.AsCharString(),
		failure.fileName_	.AsCharString(),
		failure.lineNumber_)
	;
}

void TestResult::TestsEnded(
		int testsNumber) 
{
	fprintf (stdout, "Statistics: %ld checks in %ld tests were made. ",allCheckCount_,testsNumber);
	if (failureCount_ > 0)
		fprintf (stdout, "There were %ld failures.\n", failureCount_);
	else
		fprintf (stdout, "There were no test failures.\n");
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Israel Israel
MSc in System Engineering from Tallinn Technical University, Estonia. Currently, I work in a hitech enterprise in Israel.

Comments and Discussions