Cppunit
+Visual Studio
本授權條款允許使用者重製、散布、傳輸著作,但不得為商業目的之使用,亦不得
修改該著作。使用時必須按照著作人指定的方式表彰其姓名。
Unit test 之前
都怎麼做測試的?
在開始之前
參考:Cppunit cookbook, Simple Test Case
鷹架程式碼
鷹架程式碼+條件編譯
Debugger
(略~想像各位都會此招了)
優缺點?
• 鷹架程式碼
• 優:每次都會call檢查的程式碼,有夠方便!
• 缺:效能!產品code的效能就這樣犧牲了!
• 鷹架程式碼+條件編譯
• 優:帥呀!debug才會犧牲效能!產品code就沒問題了!
• 缺:可讀性!整個程式都在看這些不會執行的code就飽了?
• Debugger
• 優:更帥!整個程式都乾乾淨淨的了!
• 缺:(人工)找一支蟲,要花多少青春歲月?
如果用Unit Test
優:
• 程式碼對程式碼測試。快!
• 測試這次出錯的code,下次可以用。可累積!
• 獨立於產品code。產品code可讀性高!
• 測試項目各自獨立,一條一條如同規格書。會執行的規格書!
缺:
• 要學一下!
用CppUnit做unit test
正片開始
CppUnit
→下載←
編譯
使用
+Visual Studio
+Windows
下載CppUnit
誰不會?
Cppunit 下載
1. Google
Cppunit 下載
1. Google  1.12.1
Cppunit 下載
1. Google: cppunit  1.12.1
Cppunit 下載
1. Google: cppunit  1.12.1
2. Google: cppunit wiki  1.13.2
Cppunit 下載
1. Google: cppunit  1.12.1
2. Google: cppunit wiki  1.13.2
增加支援windows 64bit的編譯
Visual Studio
CppUnit 1.13.2
下載成功!
CppUnit
下載
→編譯←
使用
+Visual Studio
+Windows
都用Visual Studio了!誰不會Build?
CppUnit 1.13.2
自帶
VC6.vcproj
和
VS2010.vcproj
由於,當時較熟悉的工具
是VC6,先試試VC6
但是….考慮到大家不用古董…
參考:C++單元測試(2) - 用VC6編譯CppUnit
就只提一下重點
• cdxCDynamicDialog.cpp(30) : error C2440 這是timer的參數型別出問題。
• TreeHierarchyDlg.cpp(106) : error C2065 m_treeTests.SetItemData(...) 參數型別出問題。
• TreeHierarchyDlg.cpp(188) : error C2065 Text::data; 型別出問題
參考:C++單元測試(2) - 用VC6編譯CppUnit
再回到
CppUnit 1.13.2
自帶
VC6.vcproj
和
VS2010.vcproj
這次用第二個
Cppunit建議VS版本 - VS2010。
只要打開專案檔,按下建置,就過了?!
還有一個….
如果我想用其它版本的Visual Studio呢?
再試
Visual Studio 2005
只要打開專案檔,按下建置,就過了?!
Visual Studio 2005
只要打開專案檔 --- False
意思是,版本錯誤!
參考:C++單元測試(8) - 再用VS2005先試一下: 專案檔轉換失敗
Visual Studio 2005
只要打開專案檔 --- False
意思是,版本錯誤!
什麼?!><
崩潰!( ▔皿▔) 這?
VS不是地球上最吸錢的強大工具
參考:C++單元測試(8) - 再用VS2005先試一下: 專案檔轉換失敗
回到正題
Visual Studio 2005
用文字編輯器打開.vcproj
1. Version="9.00"改成Version="8.00"
(數字大於8.00,才改成8.00)
2. TargetFrameworkVersion="**" 刪除
(不管數字是什麼!刪!)
修改專案檔
將cppunit/src底下所有的.vcproj找出來
總共有8個。
1. cppunit.vcproj
2. cppunit_dll.vcproj
3. qttestrunner_dll.vcproj
4. TestPlugInRunner.vcproj
5. TestRunner.vcproj
6. DllPlugInTester.vcproj
7. DllPlugInTesterTest.vcproj
8. qttestrunner.vcproj
參考:C++單元測試(8) - 再用VS2005先試一下: 專案檔轉換失敗
CppUnit
下載
編譯
→使用←
+Visual Studio
+Windows
真正的正片開始
也許這是今天大家想要來聽的
使用CppUnit
因為CppUnit是單元測試框架,所以….
使用CppUnit
要找到對的
被測試程式
測試程式
使用CppUnit
最重要的
就是要能執行!
使用CppUnit
最初可以用來測試環境測試的code
1. 官網的文章 - 英文版
2. CppUnit CookBook 中文版 - 簡中版
3. CppUnit食譜 - 正體中文版 ← 推薦
4. CppUnit 快速上手 - 正體中文版
5. 還有一個…
使用CppUnit
最初可以用來測試環境測試的code
• 游戏编程精粹6
使用CppUnit – CppUnit CookBook
fixture
tset case
test caller
test suite
test caller
tset case
suite.run
runner
main
參考:CppUnit 食譜 - 正體中文版
使用CppUnit –
CppUnit CookBook
1. 建立一個fixture
2. 建立tset case函數
3. 用test caller呼叫一個test case函數
4. 測試結果TestResult,用caller.run(&result)。
5. 用test suite加入很多個test caller。
6. 測試結果TestResult,用suite.run(&result)。
以及使用Marco簡化語法
fixture
tset case
test caller
test suite
test caller
tset case
參考:CppUnit 食譜 - 正體中文版
使用CppUnit –
CppUnit CookBook
1. 先在fixture建立static函數suite()。
2. 在主程式用TestRunner加入fixture::sutie的回傳值。
3. runner.run();執行整個單元測試專案。
以及使用Marco簡化語法
suite.run
runner
main
參考:CppUnit 食譜 - 正體中文版
使用CppUnit –
CppUnit CookBook
CookBook的步驟很多。
最後一版的程式在這
在此直接拿來用
程式碼
main.cpp
Complex.h /.cpp
cppUnitMain.cpp
ComplexNumberTest.h /.cpp
cppUnitLib.h
參考:CppUnit 食譜 - 正體中文版
使用CppUnit
VC6
先看專案檔與檔案之間的設定
(此專案檔都是Win32 Console Application)
VS2010
此專案是由空專案開始,加上.cpp和.h
使用CppUnit
VC6
先看專案檔與檔案之間的設定
(此專案檔都是Win32 Console Application)
就不介紹古董級的工具了
VS2010
此專案是由空專案開始,加上.cpp和.h
使用CppUnit
設定專案檔屬性
.h檔路徑
參考:C++單元測試(5) - 再用VS2010先試一下: 如何使用CppUnit
使用CppUnit
設定專案檔屬性
lib檔的路徑
參考:C++單元測試(5) - 再用VS2010先試一下: 如何使用CppUnit
使用CppUnit
設定專案檔屬性
lib檔的檔案名稱
參考:C++單元測試(5) - 再用VS2010先試一下: 如何使用CppUnit
貼程式碼!
C++單元測試(4) - 用VC6先試一下: 如何使用CppUnit
Cook book 練習中,最後的程式碼
執行!
如果…編譯成功
使用CppUnit
設定UnitTest為Active Project就可以「以
Unit Test為主」
在IDE按下編譯→執行,就可以看見Unit
Test的執行結果報告了!^^
可能遇到的問題
• Visual studio專案檔轉換問題
• warning C4251+error LNK1123
• VS2005 msvcprtd.lib(MSVCP80D.dll) : error LNK2005
• cdxCDynamicDialog.cpp(30) : error C2440
CppUnit + Jenkins
有機會再說了

More Related Content

PPTX
Roys ppt
PPTX
Katharine Kolcaba's Theory of Comfort: A Theory Critique
PPT
Malaria by Dr Sanaa Ibnouf
DOC
Nurse Staffing And Quality Of Careللطالب عامر آل الري
PDF
Complete LSS Manual 4th edition compiled by Dr. Adesanya, Ezekiel O. MB;BS-LTH
PPTX
martha rogers
PPTX
NUR125 Clinical Placement and Portfolio
Roys ppt
Katharine Kolcaba's Theory of Comfort: A Theory Critique
Malaria by Dr Sanaa Ibnouf
Nurse Staffing And Quality Of Careللطالب عامر آل الري
Complete LSS Manual 4th edition compiled by Dr. Adesanya, Ezekiel O. MB;BS-LTH
martha rogers
NUR125 Clinical Placement and Portfolio

What's hot (7)

PPTX
Paplau theory of interpersonal relationship
PPTX
Need assessment as a first step of training
PPTX
Nursing Leadership and Management
PPTX
Hepatitis
PPTX
Concept of disease causation
PPTX
Abdellah's ppt current
PPT
Development of ntp bsc
Paplau theory of interpersonal relationship
Need assessment as a first step of training
Nursing Leadership and Management
Hepatitis
Concept of disease causation
Abdellah's ppt current
Development of ntp bsc
Ad

More from Chris Wang (20)

PDF
屏東縣政府112年度大專青年公部門暑期工讀計畫簡章.pdf
PDF
「設計」在工程師職涯中 扮演的角色
PDF
歡迎加入軟體構築行列
PDF
自我探索的資訊教育
PDF
完美 camp 進化論
PPTX
Dm create message old
PPTX
Dm create message new
PPTX
用 jenkins 實戰 CD/CI
PPTX
MVC Design in Web backend Server
PPT
Bug afx ini-line122
PPT
物件的值莫名奇妙被改掉
PPT
VC6 font setup tips
PPT
MFC tips for single document
PPT
CString of MFC skills
PPT
應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片
PDF
偷偷學習 Python3
PDF
思考 Vuex 發送 API 的架構
PDF
從 Flux 認識 vuex
PDF
Information architecture reading ch7
PPTX
用Vue改dom
屏東縣政府112年度大專青年公部門暑期工讀計畫簡章.pdf
「設計」在工程師職涯中 扮演的角色
歡迎加入軟體構築行列
自我探索的資訊教育
完美 camp 進化論
Dm create message old
Dm create message new
用 jenkins 實戰 CD/CI
MVC Design in Web backend Server
Bug afx ini-line122
物件的值莫名奇妙被改掉
VC6 font setup tips
MFC tips for single document
CString of MFC skills
應用於液晶電視中動態背光調光技術之演算法與系統整合實現 論文口試投影片
偷偷學習 Python3
思考 Vuex 發送 API 的架構
從 Flux 認識 vuex
Information architecture reading ch7
用Vue改dom
Ad

Cppunit下載、編譯、使用與困難排除