狠狠撸

狠狠撸Share a Scribd company logo
如何在實務上使用TDD來開發
Joey Chen(91)
? Microsoft MVP 2010~2013
? C#
? 共同作者, 書籍譯者
? 軟體工程, 測試, 重構, CI, TDD, BDD…
2
About 91
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
? Web UI Testing
? Refactoring
? Unit Testing
? BDD
? Interface
? 第一式打到最後一式
20
Agenda
twMVC#12 | 如何在實務上使用 TDD 來開發
22
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
? Record Scenarios
? Replay and Assert
? Export to C#
? Auto testing in C#
Demo
33
Demo – Selenium IDE & C#
? Selenium IDE
? [Selenium IDE]Export to C#/WebDriver/MSTest
? NuGet
? Selenium WebDriver
? Selenium WebDriver Support Classes
Reference
35
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
Demo – Extract Method
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
Demo – 建立Class
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
Demo – 單元測試
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
Visual Studio Extension
NuGet
App.Config
<unitTestProvider name="MsTest" />
Scenarios
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
Demo – Specflow
? Specflow
? Specflow Visual Studio Extension
? NuGet
? Specflow
Reference
67
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
Demo – Extract Interface
? Web UI testing (acceptance testing)
? Unit testing
? Test cases by scenarios
? Depend on interface
Recap
73
twMVC#12 | 如何在實務上使用 TDD 來開發
PO:
twMVC#12 | 如何在實務上使用 TDD 來開發
Team:
PO:
PO:
Team:
? 帳號輸入 joey
? 密碼輸入 1234
? 登入成功
? 導到首頁 ~/Home/Index
PO & team – 登入成功
81
? 帳號輸入 joey
? 密碼輸入 abc
? 登入失敗
? 呈現錯誤訊息為 “帳號或密碼有誤”
PO & team – 登入失敗
82
Team:
Demo – Prototype confirm
PO:
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
Demo – Describe Scenarios
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
Demo – Selenium testing
twMVC#12 | 如何在實務上使用 TDD 來開發
? Account 傳入 joey
? Password 傳入 1234
? 結果
? Controller 應為 Home
? Action 應為 Index
登入成功
95
? Account 傳入 joey
? Password 傳入 abc
? 結果
? ViewBag.Message 為帳號或密碼有誤
登入失敗
96
Demo – Controller’s testing
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
Mock framework - RhinoMocks
RhinoMocks
RhinoMocks
Demo – IoC & Stub
Mock framework
Without DI
DI framework – Unity.MVC4
Container.RegisterType<TFrom,TTo>
Demo – DI & MyAuthentication
twMVC#12 | 如何在實務上使用 TDD 來開發
Get Password from Data Source
Hash Password to Compare
twMVC#12 | 如何在實務上使用 TDD 來開發
? IAccountDao的GetPassword方法,傳入”joey”,回傳
“Joey hashed password”
? IHash的GetHashResult方法,傳入”1234”,回傳“Joey
hashed password”
? 結果
? True
IAccountDao回傳與IHash結果相同
115
? IAccountDao的GetPassword方法,傳入”joey”,回傳
“Joey hashed password”
? IHash的GetHashResult方法,傳入”abc”,回傳“abc
hashed result”
? 結果
? False
IAccountDao回傳與IHash結果不同
116
Demo – MyAuthentication BDD
twMVC#12 | 如何在實務上使用 TDD 來開發
實作 IAccountDao
MyAccountDao with hard-code
實作 IHash
MyHash with hard-code
Container.RegisterType
Demo – MyAccountDao & MyHash
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
需求
雛形
Selenium
Test
Controller
Test
IAuthentication
DI with
MyAuthentication
Controller
Test
IAccountDao
IHash
DI with
MyAuthentication
MyAuthentication
Testing
MyAccountDao
MyAuthentication
Testing
MyHash
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
twMVC#12 | 如何在實務上使用 TDD 來開發
你也可以!
Q & A
Thanks for your listening
137
謝謝各位
? 本投影片所包含的商標與文字皆屬原著作者所有。
? 本投影片使用的圖片皆從網路搜尋。
? 本著作係採用 Creative Commons 姓名標示-非商業性-相同方式分享 3.0 台灣 (中華民國) 授權條款授權。
h t t p : / / m v c . t w

More Related Content

What's hot (17)

PDF
如何在實務上使用TDD來開發 twmvc#12
twMVC
?
DOCX
zhuwenlongChinese
Wenlong Zhu
?
PDF
ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3
twMVC
?
PDF
ASP.NET MVC之實戰架構探討 -twMVC#5
twMVC
?
PDF
ASP.NET MVC 新增、查詢、修改、刪除 基本功實戰 -twMVC#3
twMVC
?
PDF
twMVC#20 | ASP.NET MVC View 開發技巧小錦囊
twMVC
?
PPTX
twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC
?
PPTX
KSDG-ASP.NET MVC 5 Overview (偽三國誌)
Bruce Chen
?
PDF
輕鬆上手Asp.net web api 2.1-twMVC#14
twMVC
?
PDF
开发的效能与效率-迟飞惭痴颁#15
twMVC
?
PDF
twMVC#05 |開發與移轉 ASP.NET MVC 4.0 應用程式到 Windows Azure Platform
twMVC
?
PDF
twMVC#22 | 什麼鬼的IOC與DI
twMVC
?
PPTX
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
Duran Hsieh
?
PDF
twMVC#24 | 開發團隊的敏捷之路(未完成)
twMVC
?
PDF
ASP.NET MVC 4 新功能介紹(快速上手) -twMVC#4
twMVC
?
PDF
twMVC#19 | 微信公眾平台申請與wechat api 開發血淚史
twMVC
?
PDF
twMVC#28 | visual studio 2017 新功能介紹
twMVC
?
如何在實務上使用TDD來開發 twmvc#12
twMVC
?
zhuwenlongChinese
Wenlong Zhu
?
ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3
twMVC
?
ASP.NET MVC之實戰架構探討 -twMVC#5
twMVC
?
ASP.NET MVC 新增、查詢、修改、刪除 基本功實戰 -twMVC#3
twMVC
?
twMVC#20 | ASP.NET MVC View 開發技巧小錦囊
twMVC
?
twMVC#01 | ASP.NET MVC 的第一次親密接觸
twMVC
?
KSDG-ASP.NET MVC 5 Overview (偽三國誌)
Bruce Chen
?
輕鬆上手Asp.net web api 2.1-twMVC#14
twMVC
?
开发的效能与效率-迟飞惭痴颁#15
twMVC
?
twMVC#05 |開發與移轉 ASP.NET MVC 4.0 應用程式到 Windows Azure Platform
twMVC
?
twMVC#22 | 什麼鬼的IOC與DI
twMVC
?
2016年逢甲大學資訊系:ASP.NET MVC 4 教育訓練4
Duran Hsieh
?
twMVC#24 | 開發團隊的敏捷之路(未完成)
twMVC
?
ASP.NET MVC 4 新功能介紹(快速上手) -twMVC#4
twMVC
?
twMVC#19 | 微信公眾平台申請與wechat api 開發血淚史
twMVC
?
twMVC#28 | visual studio 2017 新功能介紹
twMVC
?

Similar to twMVC#12 | 如何在實務上使用 TDD 來開發 (20)

PPTX
Web testing automation
kuozui
?
PDF
打造面向服务的敏捷团队 Q con-beijing2012
Qiao Liang
?
PDF
service-oriented agile team-Q con-beijing2012
Qiao Liang
?
PPTX
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Gelis Wu
?
PPT
PHP 单元测试
Lan Yanguang
?
PDF
Unit test
shan chen
?
PPTX
用 Drone 打造 輕量級容器持續交付平台
Bo-Yi Wu
?
PPT
颁#语言与面向对象程序设计
WizRay
?
PDF
[DevOpsDays] 硬體產業的DevOps導入與實踐 - 以工控產業為例
TIM WANG
?
PPT
The way to continuous delivery
Qiao Liang
?
PDF
嵌入式测试驱动开发
hugo lu
?
PPT
2014/02: 嵌入式测试驱动开发
AgileCommunity
?
PDF
Continuous integration
netdbncku
?
PDF
和Android源代码一起工作 | 海豚浏览器 胡继堂
imShining @DevCamp
?
PDF
Windows 市集應用程式 開發心得分享 -twMVC#6
twMVC
?
PDF
twMVC#06 | Wiindows市集應用程式 開發心得分享
twMVC
?
PDF
Foundation of software development 1
netdbncku
?
PPTX
在B2B硬體產業運用 Agile 與 DevOps 的實務與心法
TIM WANG
?
DOC
2006年招聘试题
yiditushe
?
PDF
Xpp
drewz lin
?
Web testing automation
kuozui
?
打造面向服务的敏捷团队 Q con-beijing2012
Qiao Liang
?
service-oriented agile team-Q con-beijing2012
Qiao Liang
?
Visual studio 2012 與 asp.net 4.5 (新功能與開發介紹) 第一天
Gelis Wu
?
PHP 单元测试
Lan Yanguang
?
Unit test
shan chen
?
用 Drone 打造 輕量級容器持續交付平台
Bo-Yi Wu
?
颁#语言与面向对象程序设计
WizRay
?
[DevOpsDays] 硬體產業的DevOps導入與實踐 - 以工控產業為例
TIM WANG
?
The way to continuous delivery
Qiao Liang
?
嵌入式测试驱动开发
hugo lu
?
2014/02: 嵌入式测试驱动开发
AgileCommunity
?
Continuous integration
netdbncku
?
和Android源代码一起工作 | 海豚浏览器 胡继堂
imShining @DevCamp
?
Windows 市集應用程式 開發心得分享 -twMVC#6
twMVC
?
twMVC#06 | Wiindows市集應用程式 開發心得分享
twMVC
?
Foundation of software development 1
netdbncku
?
在B2B硬體產業運用 Agile 與 DevOps 的實務與心法
TIM WANG
?
2006年招聘试题
yiditushe
?
Ad

More from twMVC (20)

PDF
twMVC#51 以平台工程重新思考系統設計 - 以 Batch System 為例封面
twMVC
?
PDF
twMVC#51-GitHub Copilot 徹底改變開發模式,探索 AI 驅動的智慧程式碼協作
twMVC
?
PDF
twMVC#50 微服務上線後的救贖
twMVC
?
PDF
twMVC 47_Elastic APM 的兩三事
twMVC
?
PDF
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC
?
PDF
.NET 7 家族新成員: Microsoft Orleans v7
twMVC
?
PDF
twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC
?
PDF
twMVC#44 如何測試與保護你的 web application with playwright
twMVC
?
PDF
twMVC#44 讓我們用 k6 來進行壓測吧
twMVC
?
PDF
twMVC#43 Visual Studio 2022 新功能拆解
twMVC
?
PDF
twMVC#43 YARP
twMVC
?
PDF
twMVC#43 C#10 新功能介紹
twMVC
?
PDF
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用
twMVC
?
PDF
twMVC#42 Azure IoT Hub for Smart Factory
twMVC
?
PDF
twMVC#42 Windows容器導入由0到1
twMVC
?
PDF
twMVC#42 讓我們用一種方式來開發吧
twMVC
?
PDF
twMVC#41 hololens2 MR
twMVC
?
PPTX
twMVC#41 The journey of source generator
twMVC
?
PDF
twMVC#38 How we migrate tfs to git(using azure dev ops)
twMVC
?
PDF
迟飞惭痴颁#36颁#的美丽与哀愁
twMVC
?
twMVC#51 以平台工程重新思考系統設計 - 以 Batch System 為例封面
twMVC
?
twMVC#51-GitHub Copilot 徹底改變開發模式,探索 AI 驅動的智慧程式碼協作
twMVC
?
twMVC#50 微服務上線後的救贖
twMVC
?
twMVC 47_Elastic APM 的兩三事
twMVC
?
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC
?
.NET 7 家族新成員: Microsoft Orleans v7
twMVC
?
twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC
?
twMVC#44 如何測試與保護你的 web application with playwright
twMVC
?
twMVC#44 讓我們用 k6 來進行壓測吧
twMVC
?
twMVC#43 Visual Studio 2022 新功能拆解
twMVC
?
twMVC#43 YARP
twMVC
?
twMVC#43 C#10 新功能介紹
twMVC
?
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用
twMVC
?
twMVC#42 Azure IoT Hub for Smart Factory
twMVC
?
twMVC#42 Windows容器導入由0到1
twMVC
?
twMVC#42 讓我們用一種方式來開發吧
twMVC
?
twMVC#41 hololens2 MR
twMVC
?
twMVC#41 The journey of source generator
twMVC
?
twMVC#38 How we migrate tfs to git(using azure dev ops)
twMVC
?
迟飞惭痴颁#36颁#的美丽与哀愁
twMVC
?
Ad

twMVC#12 | 如何在實務上使用 TDD 來開發