[英]DUnit on older C++Builder versions?
當前,我們正在將在C ++ Builder 5下開發的源遷移到較新的Embarcadero的XE5。 提前考慮,我們想在C ++ Builder5下編寫單元測試,理想情況下,在移植后幾乎不需要維護就可以正常運行。
我的問題很簡單。 可以使用Embarcadero在C ++ Builder 5上使用的同一DUnit框架嗎? 如果是這樣,您能給我們提供任何提示嗎?
謝謝。
DUnit確實可以在CppBuilder5上使用。 為此:
使用以下命令行構建DUNITRTL.lib,或者可以制作一個.bat文件並從/ dunit / src文件夾執行該文件:
SET NDC6=C:\\PROGRA~2\\Borland\\CBUILD~1 %NDC6%\\bin\\dcc32.exe Dunit.dpr /O..\\objs /DBCB /M /H /W /JPHN -$dl-n+p+rstwy- %2 %3 %4 %NDC6%\\bin\\tlib.exe DUNITRTL.lib /P32 -+dunit.obj -+DunitAbout.obj -+DUnitMainForm.obj -+GUITestRunner.obj -+TestExtensions.obj -+TestFramework.obj -+TestModules.obj -+TextTestRunner.obj
完成后,進行測試項目變得容易:
#include <vcl.h>
#pragma hdrstop
#include <GUITestRunner.hpp>
USERES("Project1.res");
USELIB("DUNITRTL.lib");
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Guitestrunner::RunRegisteredTests();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}
MyTestCase.h
//---------------------------------------------------------------------------
#ifndef __TMYTESTCASE_H__
#define __TMYTESTCASE_H__
//---------------------------------------------------------------------------
#include <TestFramework.hpp>
class TMyTestCase : public TTestCase
{
public:
__fastcall virtual TMyTestCase(AnsiString name) : TTestCase(name) {}
virtual void __fastcall SetUp();
virtual void __fastcall TearDown();
__published:
void __fastcall MySuccessfulTest();
void __fastcall MyFailedTest();
};
#endif
MyTestCase.cpp
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#include "TMyTestCase.h"
//---------------------------------------------------------------------------
void __fastcall TMyTestCase::SetUp()
{}
void __fastcall TMyTestCase::TearDown()
{}
void __fastcall TMyTestCase::MySuccessfulTest()
{
int a = 1;
a = a + 1;
CheckEquals(2,a,"test adding");
}
void __fastcall TMyTestCase::MyFailedTest()
{
int a = 1;
a = a + 2;
CheckEquals(2,a,"test adding");
}
static void registerTests()
{
_di_ITestSuite iSuite;
TTestSuite* testSuite = new TTestSuite("Testing TMyTestCase.h");
if (testSuite->GetInterface(__uuidof(ITestSuite), &iSuite))
{
testSuite->AddTests(__classid(TMyTestCase));
Testframework::RegisterTest(iSuite);
}
else
{
delete testSuite;
}
}
#pragma startup registerTests 33
#pragma package(smart_init)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.