[測試(Testing)]
打開工作區(qū)文件examples/Examples.dsw。
將CppUnitTestApp設為active project.
為你要創(chuàng)建的庫選擇合適的配置。
編譯運行project。TestRunner GUI將會出現(xiàn)。
[庫(Libraries)]
所有編譯后生成的庫均可在'lib'目錄中找到。多數(shù)庫可以在src/CppUnitLibraries.dsw工作區(qū)中創(chuàng)建。
lib:
cppunit.lib : CppUnit靜態(tài)庫“Multithreaded DLL”
cppunitd.lib : CppUnit靜態(tài)庫“Debug Multithreaded DLL”
cppunit_dll.dll : CppUnit動態(tài)庫(DLL)“Multithreaded DLL”
cppunit_dll.lib : CppUnit動態(tài)導入庫“Multithreaded DLL”
cppunitd_dll.dll : CppUnit動態(tài)庫(DLL)“Debug Multithreaded DLL”
cppunitd_dll.lib : CppUnit動態(tài)導入庫“Debug Multithreaded DLL”
qttestrunner.dll : QT TestRunner動態(tài)庫(DLL)“Multithreaded DLL”
qttestrunner.lib : QT TestRunner導入庫“Multithreaded DLL”
testrunner.dll : MFC TestRunner動態(tài)庫(DLL)“Multithreaded DLL”
testrunner.lib : MFC TestRunner導入庫“Multithreaded DLL”
testrunnerd.dll : MFC TestRunner動態(tài)庫(DLL)“Debug Multithreaded DLL”
testrunnerd.lib : MFC TestRunner導入庫“Debug Multithreaded DLL”
testrunneru.dll : MFC Unicode TestRunner動態(tài)庫(DLL)“Multithreaded DLL”
testrunneru.lib : MFC Unicode TestRunner導入庫“Multithreaded DLL”
testrunnerud.dll : MFC Unicode TestRunner動態(tài)庫(DLL)“Debug Multithreaded DLL”
testrunnerud.lib : MFC Unicode TestRunner導入庫“Debug Multithreaded DLL”
TestRunnerDSPlugIn.dll : 注冊到你的VC++中的附加件。
注意:當你使用CppUnit DLL(cppunit*_dll.dll)時,你必須連接相關的導入庫,并在project中定義預處理標識CPPUNIT_DLL。
[使用CppUnit]
編寫單元測試:
為了編寫單元測試,你需要連接cppunitXX.lib,此處的XX即所選配置對應的后綴字母。 你必須在你的project中打開RTTI開關(Project Settings/C++/C++ Language)。 CppUnit的include目錄必須包含在include查找路徑中。你可以通過在Project Settings/C++/Preprocessor/Additional include directories或者Tools/Options/Directories/Include中添加include目錄做到這一點。
簡言之:
打開RTTI開關
連接lib/cppunitXX.lib
include/ 必須包含在include查找路徑中
使用TestRunner GUI:
為了使用GUI的test runner,你需要連接testrunnerXX.lib和cppunitXX.lib,此處的XX即所選配置對應的后綴字母。 你必須在你的project中打開RTTI開關。 文件testrunner.dll必須位于你的應用程序所在的路徑(Debug或Release目錄,project的dsp文件所在目錄,或環(huán)境變量PATH中所指定的目錄)。 一個簡單的辦法是,要么添加一個post-build命令,或者,將位于lib/目錄下的testrunner.dll添加到你的project中來,并定制創(chuàng)建步驟,將dll文件拷貝到你的“中間結果”目錄(通常是Debug或Release目錄)。
因為TestRunner GUI是一個MFC的擴展DLL,它能夠訪問當前應用程序的CWinApp。 參數(shù)設置將使用應用程序的注冊鍵。這意味著,設置項“近使用的測試”對每個應用程序而言都是不同的。
簡言之:
打開RTTI開關
連接lib/cppunitXX.lib和lib/testrunnerXX.lib
include/必須包含在include查找路徑中
為了運行你的project,lib/testrunnerXX.dll必須可用
使用DSPlugIn:
你必須在VC++中注冊該插件。在Tools/Customize/Add-ins and Macro files中點擊browse,并選擇lib/TestRunnerDSPlugIn.dll(你可以注冊release版或者debug版,都能運行)。
若VC++正在運行,當你雙擊一個failure后,VC++將打開相關文件并定位到出錯行。
使用Test Plug In Runner:
你的DLL必須導出(export)一個函數(shù),該函數(shù)實現(xiàn)了在include/msvc6/testrunner/TestPlugInInterface.h中所定義的接口。作為范例,參見examples/msvc6/TestPlugIn/TestPlugInInterfaceImpl.*。注意:該runner仍處于實驗階段并未作足夠多的測試。