Rajinder Yadav - Windows/Linux C++ Development Tools & Resources :Design, Code, Test, Deploy
Global Definitions
UnitTest.h
UnitTestDefs.h
Core Project Files
IUnitTestRunner.h
IUnitTestObserver.h
UnitTestRunner.h
UnitTestRunner.cpp
UnitTestAssembly.h
UnitTestAssembly.cpp
Observers
ConsoleLogger.h
ConsoleLogger.cpp
StreamLogger.h
StreamLogger.cpp
C++ Standard Type Library

UnitTest Framework Architectual Notes


Interface IUnitTestRunner
This is the interface used by the Unit Test framework to notify the subject (unit test class) of test events.

struct IUnitTestRunner
{
   
virtual void Setup()   0;   // called before each unit test starts
   
virtual void CleanUp() 0;   // called after each unit test has completed
   
virtual void RunTest() 0;   // called ONCE for each test class
};

Class UnitTestRunner
Each subject (unit test class) that the Users codes, will contain one or more unit test cases. The UnitTestRunner implements the base logic for running a unit test and maintaining unit test statistics resulting from the User's unit test class. The class implements the interface IUnitTestRunner that is used to control the events that get generated. These events are:

EventDescription
SetupCalled before each unit test case is executed.
RunTestCalled to begin execution of the unit test in the test class.
CleanUpCalled after each unit test case has been executed.

The class UnitTestRunner also acts as a container for unit test observers that are notified of test events and conditions. Unit test observer are added and removed to the UnitTestRunner by the UnitTestAssembly class.

For each test case executed, class UnitTestRunner puts intermediate test results into the string buffer m_strMessageStream, this string buffer is used to pass on test results to attached unit test observers. The string buffer m_strMessageStream gets reset before the execution of the next test case.

The User's unit test class is derived from class UnitTestRunner and is what gets registered with the UnitTest framework.

UnitTestAssembly
This class is responsible for running all test cases, it also manages them by acting as a unit test container. Each User's test class needs to register itself with the UnitTestAssembly for unit testing.

Unit testing happens by iterating through the list of registered subjects (Unit Test Classes) and calling their Run( ) method.

All unit test observers need to register with the UnitTestAssembly. The UnitTestAssembly inturn takes care of registering each observer with each subject to allow the observer to be notified of test case events.

Home

Copyright © 2007 Rajinder Yadav, All rights reserved