CPPUnit은 이미 시스템에 설치되어 있다고 가정한다.
설치하는 방법App 클래스에 대해서 할 작업 ===========================1. 테스트 프로젝트의 App 클래스(CWinApp로부터 파생되는 클래스) 구현 파일에 다음 두 개의 인클루드문을 추가한다.
#include <msvc6/testrunner/testrunner.h>
#include <cppunit/extensions/testfactoryregistry.h>
2. App 클래스 InitInstance 함수에 TestRunner를 동작시키는 다음 코드를 추가한다.
TestRunner runner;
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
runner.run();
테스트 메소드를 작성할 테스트 클래스 작성 ===========================1. 프로젝트에 테스트 메소드를 작성할 클래스를 추가한다.
이 클래스는 반드시
CppUnit::TestCase 으로부터 파생되어야 한다.
헤더파일(Test_PrinterInfo.h)
// 실제로 구현하게 될 CPrinterInfo 클래스를 테스트할 목적으로 만든 테스트 클래스
//////////////////////////////////////////////////////////////////////
#ifndef __TEST_PRINTERINFO_H__
#define __TEST_PRINTERINFO_H__
#include <cppunit/TestCase.h>
#include <cppunit/extensions/HelperMacros.h>
class CTest_PrinterInfo : public CppUnit::TestCase
{
public:
CTest_PrinterInfo();
virtual ~CTest_PrinterInfo();
};
#endif // #ifndef __TEST_PRINTERINFO_H__
구현파일(Test_PrinterInfo.cpp)
// Test_PrinterInfo.cpp: implementation of the CTest_PrinterInfo class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test_PrinterInfo.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTest_PrinterInfo::CTest_PrinterInfo()
{
}
CTest_PrinterInfo::~CTest_PrinterInfo()
{
}
2. 이 클래스가 CPPUnit을 사용할 수 있게 하기 위한 매크로를 추가한다.
헤더파일
// 실제로 구현하게 될 CPrinterInfo 클래스를 테스트할 목적으로 만든 테스트 클래스
//////////////////////////////////////////////////////////////////////
#ifndef __TEST_PRINTERINFO_H__
#define __TEST_PRINTERINFO_H__
#include <cppunit/TestCase.h>
#include <cppunit/extensions/HelperMacros.h>
class CTest_PrinterInfo : public CppUnit::TestCase
{
// TestSuite
CPPUNIT_TEST_SUITE( CTest_PrinterInfo );
// TestCase 의 등록.
CPPUNIT_TEST_SUITE_END();
public:
CTest_PrinterInfo();
virtual ~CTest_PrinterInfo();
};
#endif // #ifndef __TEST_PRINTERINFO_H__
구현파일
// Test_PrinterInfo.cpp: implementation of the CTest_PrinterInfo class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test_PrinterInfo.h"
CPPUNIT_TEST_SUITE_REGISTRATION( CTest_PrinterInfo ); // 등록!!!
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTest_PrinterInfo::CTest_PrinterInfo()
{
}
CTest_PrinterInfo::~CTest_PrinterInfo()
{
}
3. 테스트 메소드를 추가하고 CPPUnit 매크로를 추가하여 TestCase로서 등록한다.
헤더파일
// 실제로 구현하게 될 CPrinterInfo 클래스를 테스트할 목적으로 만든 테스트 클래스
//////////////////////////////////////////////////////////////////////
#ifndef __TEST_PRINTERINFO_H__
#define __TEST_PRINTERINFO_H__
#include <cppunit/TestCase.h>
#include <cppunit/extensions/HelperMacros.h>
class CTest_PrinterInfo : public CppUnit::TestCase
{
// TestSuite
CPPUNIT_TEST_SUITE( CTest_PrinterInfo );
// TestCase 의 등록.
CPPUNIT_TEST( Test_GetPrinterInfo );
CPPUNIT_TEST_SUITE_END();
public:
CTest_PrinterInfo();
virtual ~CTest_PrinterInfo();
protected:
void Test_GetPrinterInfo();
};
#endif // #ifndef __TEST_PRINTERINFO_H__
구현파일
// Test_PrinterInfo.cpp: implementation of the CTest_PrinterInfo class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Test_PrinterInfo.h"
CPPUNIT_TEST_SUITE_REGISTRATION( CTest_PrinterInfo ); // 등록!!!
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTest_PrinterInfo::CTest_PrinterInfo()
{
}
CTest_PrinterInfo::~CTest_PrinterInfo()
{
}
void CTest_PrinterInfo::Test_GetPrinterInfo()
{
}
4. 프로젝트 셋팅에 두 개의 lib 파일에 대한 링크를 걸어준다.
cppunitd.lib testrunnerd.lib
릴리즈 버전일 때는
cppunit.lib testrunner.lib
5. 프로젝트 셋팅에서 C/C++, C++ Language 항목의
Enable Run_time Type Information (RTTI)항목을 활성화시킨다.
6. 실행파일이 존재하는 디렉토리에 testrunnerd.dll 또는 testrunner.dll 이 있어야 동작을 한다는 사실...