SlideShare a Scribd company logo
William Wang
Sr. Engineer
Component Unit Test
- How we start in mobile app ?
Who am i ?
• 靠寫程式混口飯吃的哲學家
Java, Android Developer
Agile Believer
Clean Code Believer
Performance Matter
王宣皓
William Wang
We all know that
Test is important ...
Problems
1. 自動化測試很重要,但不知怎麼開始
2. 寫了UI自動化測試腳本,浪費好多撰寫成本
3. UI自動化腳本走不完所有路徑
4. UI自動化測試總是跑很慢
5. RD:Unit Test綠燈了!
QA:所以呢?可以吃嗎?
Component Unit Test
My favorite talk
Component Unit Test
Component Unit Test
Component Unit Test
Component Unit Test
How about
follow suit in the app?
Tips 1
MVP Pattern
Tips 2
API Abstraction
Transforn
VIEW
PRESENTER
MODEL
API
Mobile App Workflow
分析、委任
事件及資料
業務邏輯
解析結果顯示邏輯更新畫面 業務邏輯
解析
View事件
VIEW
PRESENTER
MODEL
API
Mobile App Workflow
分析、委任
事件及資料
業務邏輯
解析結果顯示邏輯更新畫面 業務邏輯
解析
View事件
API Test in client
E2E Validation
• 確保輸入符合Server要求、回傳「格式」符合期望
How to validate
• 輸入資料打API成功(不管回傳值正不正確)
• 解析Server回傳資料「格式」正確
■ Json參數、格式無誤
■ 轉換成Model Class無誤
VIEW
PRESENTER
MODEL
API
Mobile App Workflow
分析、委任
事件及資料
業務邏輯
解析結果顯示邏輯更新畫面 業務邏輯
解析
View事件
Model Unit Test
E2E Validation
• 業務邏輯、狀態測試
How to validate
• 輸入各種Input以並驗證期望的Output
■ 模擬Presenter呼叫的狀況
■ 不呼叫API,模擬API回傳的結果
VIEW
PRESENTER
MODEL
API
Mobile App Workflow
分析、委任
事件及資料
業務邏輯
解析結果顯示邏輯更新畫面 業務邏輯
解析
View事件
Presenter Test
E2E Validation
• Presenter:Feature的高階抽象,驗證以下行為:
■ 接收View功能性事件
■ 將功能委派給一個或多個Model
■ 通知View更新畫面
How to validate
• 驗證當事件進來時有沒有呼叫正確的Model
• 驗證Model Callback時有沒有呼叫正確的View
VIEW
PRESENTER
MODEL
API
Mobile App Workflow
分析、委任
事件及資料
業務邏輯
解析結果顯示邏輯更新畫面 業務邏輯
解析
View事件
View UI Test
E2E Validation
• 操作UI、並驗證回饋正確
How to validate
• 驗證UI事件進來時呼叫到對的Presenter方法
• 模擬Callback驗證更新View是否正確
Example
認識興趣相同的人 一起做有趣的事
我們在找同伴一起去玩,你來嗎?!
Citymate 同伴
Component Unit Test
史詩級登入流程...
Success
DEMO
Espresso
2.0
Component Unit Test
How to Design ?
Sample Class Diagram
Test UI
Mock
Espresso
Test Presenter
MockMock
Mock
Junit
Runner
Test Model
Junit
Runner
Test Model
Junit
Runner
Mock Mock
Put logic into model
Account Manager
Check
Check
Check Check
Check
No Phone First FB login No Intresting First Register
Isolate
platform, library
Component Unit Test
Dependency
Injection
public AccountManager(CitytalkPreference preference, ApiFacade apiFacade) {
this.preference = preference;
this.apiFacade = apiFacade;
……
}
public LoginPresenter(AccountManager accountManager, FacebookUtils facebookUtil, TourLoginView tourLoginView) {
mAccountManager = accountManager;
mTourLoginView = tourLoginView;
mFacebookUtil = facebookUtil;
mFbLoginCallback = new FacebookLoginCallBack();
}
Class
Lifecycle
Application
Activity
Fragment
Get Static Models
Get Local Models
Get Presenter
Let's
Discussion
&Q A
Reference
https://developers.google.com/google-test-
automation-conference/2015/presentations
- GTAC 2015: Presentations Slides

More Related Content

PDF
軟體品質與持續整合
PPTX
持續整合與單元測試
PPTX
打造完全免費的,JAVA專案持續整合環境_ 2013 java developer_day_by 李書豪
PDF
MOPCON 2015 - 軟體、測試、程式設計家
PDF
從組裝軟體中談談軟體發展管理
PDF
敏捷開花那些小事
PPTX
需求实践问题分析
PDF
Mvp in practice
軟體品質與持續整合
持續整合與單元測試
打造完全免費的,JAVA專案持續整合環境_ 2013 java developer_day_by 李書豪
MOPCON 2015 - 軟體、測試、程式設計家
從組裝軟體中談談軟體發展管理
敏捷開花那些小事
需求实践问题分析
Mvp in practice

What's hot (9)

PPTX
[VideOhya] Titanium開發經驗分享_1020
PDF
Hybrid app简要介绍
PDF
Test corner #20 誰說只有測試金字塔
PDF
互联网持续交付整形记
PDF
Beta testing with CI
PDF
Testing Automation Journey in Trend Micro
PPTX
版控實務
PDF
測試是什麼
PPTX
移动开发敏捷实践
[VideOhya] Titanium開發經驗分享_1020
Hybrid app简要介绍
Test corner #20 誰說只有測試金字塔
互联网持续交付整形记
Beta testing with CI
Testing Automation Journey in Trend Micro
版控實務
測試是什麼
移动开发敏捷实践
Ad

Similar to Component Unit Test (20)

PDF
歡迎加入軟體構築行列
PPT
The way to continuous delivery
PPT
持续交付
PPT
杨根兴 软件过程改进与敏捷方法
PDF
UiGathering Talk - Motion User Interface / by Ivan Wei
PPTX
單元測試
PDF
110929 kn-手机软件测试
PDF
Angular 深入淺出測試篇:新手入門
PDF
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
PPTX
淺談測試Part1
PDF
twMVC#23 | 一個Mobile App開發、維護與改版的愛恨之路
PDF
透過測試提升軟體品質 - twMVC#7
PDF
twMVC#07 | 透過測試提升軟體品質
PDF
Developer Series 6x6 Tour: The power of interactive ads
PPTX
Mobile app的測試v2
PDF
使用Hudson打造屬於你自己的軟體建構機器人
PPT
J2EE Performance Monitor (Profiler)
PPTX
PDF
PDF
評估驅動開發 Eval-Driven Development (EDD): 生成式 AI 軟體不確定性的解決方法
歡迎加入軟體構築行列
The way to continuous delivery
持续交付
杨根兴 软件过程改进与敏捷方法
UiGathering Talk - Motion User Interface / by Ivan Wei
單元測試
110929 kn-手机软件测试
Angular 深入淺出測試篇:新手入門
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
淺談測試Part1
twMVC#23 | 一個Mobile App開發、維護與改版的愛恨之路
透過測試提升軟體品質 - twMVC#7
twMVC#07 | 透過測試提升軟體品質
Developer Series 6x6 Tour: The power of interactive ads
Mobile app的測試v2
使用Hudson打造屬於你自己的軟體建構機器人
J2EE Performance Monitor (Profiler)
評估驅動開發 Eval-Driven Development (EDD): 生成式 AI 軟體不確定性的解決方法
Ad

Component Unit Test