Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
SpecFlow 實務經驗分享
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
LittleLin
April 20, 2017
Programming
1.4k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SpecFlow 實務經驗分享
LittleLin
April 20, 2017
More Decks by LittleLin
See All by LittleLin
如何使用 OData 來加速測試效率
kobayashi
0
1.3k
Other Decks in Programming
See All in Programming
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
780
Are APIs Still Relevant in the AI Era?
soyuka
0
460
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
230
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
470
Simple Storage Service(S3) is not simple
iwatsukayura
0
280
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
250
Kotlinの15年とServer-Side Kotlin
n_takehata
1
140
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
380
現場と育てるRailsモデリング 〜Spreadsheetから始めたモデル設計〜
siroemk
2
260
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1k
Jetpack Compose Mechanisms
skydoves
2
730
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
590
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Side Projects
sachag
456
43k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Exploring anti-patterns in Rails
aemeredith
4
540
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
700
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Bash Introduction
62gerente
615
220k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Transcript
SpecFlow 在 Yahoo! 的應⽤用實踐分享 Jonathan (⼩小林林)
關於我 ‒ Engineer @ Y! BackOffice Team ‒
[email protected]
守備範圍 ‒ 就只是個 NPC ERP ‒ .NET Tech Stack ‒
EC 訂單成立前後的⾦金金、物流
系統架構 ERP
什什麼是 SpecFlow? ‒ Cucumber(⼩小黃瓜) for .NET platform
什什麼是 Cucumber? ‒ 可執⾏行行的規格 ‒ 規格 = 測試案例例
長得像這樣
為什什麼我們使⽤用 SpecFlow?
複雜的商業邏輯
舉例例?
我們家的訂購流程 (可視部份)
簡單流程 下單 包裝 付款 完成 出貨 送達
簡單流程 下單 包裝 付款 完成 出貨 送達 付款 失敗
簡單流程 下單 包裝 付款 完成 出貨 送達 付款 失敗 缺貨
取消
簡單流程 下單 包裝 付款 完成 出貨 送達 付款 失敗 缺貨
取消 客⼾戶 拒收
想想上述情境再複雜 5~10 倍?
如何確保不會做錯 ⼤大家認知⼀一致?
將⼝口語轉為可執⾏行行規格
像這樣...
“如果徵信通過,把訂單 狀狀態更更新為 1 (付款完成)”
具體做法 撰寫 規格
撰寫規格
具體做法 撰寫 規格 讓規格 ⾃自動化 執⾏行行
⾃自動測試程式碼 (Test Code)
具體做法 撰寫 規格 撰寫程 式碼 讓規格 ⾃自動化 執⾏行行
真正運⾏行行程式碼 (Prod Code)
具體做法 撰寫 規格 撰寫程 式碼 讓規格 ⾃自動化 執⾏行行 滿⾜足 規格
規格滿⾜足
上述是 典型的 BDD 開發流程
有時候我們會這樣使⽤用 SpecFlow 現有 程式碼 讓規格 ⾃自動化 執⾏行行 整理理 規格 調整
程式
Demo
Demo - Table Schema
⽬目前看來來很不錯?
理理想是豐滿的, 現實是骨感的......
實務上我們踩過哪些 坑 & 怎麼解決?
坑 No.1 - 共⽤用開發資 料庫
共⽤用開發資料庫
這樣做有什什麼問題?
“你蓋到了了我的測試資料!”
“你測試資料沒清!”
“你測試資料清錯了了......”
解決⽅方式 ‒ 讓每個⼈人有⾃自⼰己專屬的測試庫 ‒ 使⽤用 SQL Server LocalDB (File- based
DB)
幫測試專案裝上測試 DB
調整測試專案的 Connection String
具體做法 啓動 Local DB 關閉 LocalDB 執⾏行行 測試
額外好處 ‒ Test Failed 時,LocalDB 可以⽅方便便做 為後續除錯使⽤用
Demo
坑 No.2 - 如何表達 DB 表格間的關聯聯性?
回憶我們的 Table Schema
當我們想要表達表格間 的資料關聯聯性
我們的第⼀一個測試案例例
我們的第⼀一個測試案例例
缺點 ‒ ⾁肉眼對照表格關聯聯性 ‒ 複雜度隨著表格數量量提升,等比上升
再想像我們測試案例例不 只⼀一個...
第⼆二個測試案例例
缺點 ‒ SupplierId 雖然都是 1,但真實值不 會是 1 ‒ Foreign Key
欄欄位的值,不會是真實 表格的 P.K. 值
之前的解法 ‒ 在 Feature 檔中,⼿手動做好編號 ‒ 在測試程式中,把 F.K. 欄欄位的值做替 換
‒ 表格關聯聯越多,⼯工越⼤大
後來來我們開了了個腦洞洞...
幫 Gherkin 加了了個表達 關聯聯的語法糖...
表格關聯聯語法
表格關聯聯語法
原理理︰ 新增 DB 資料時,記錄 SpecFlow Key <-> DB Key 之間的關聯聯
好處 ‒ 提⾼高表達的精確性 ‒ 減少撰寫測試程式的⼯工
Demo
Any Question?
Thank You!