2. Outline
• What's software testing
• Testing Level
• Unit Testing
o What
o Why
o Where
o Who
o When
3. What's software testing
• Software testing is operating the software under
controlled conditions,
o To verify that it behaves "as specified"
Works as expected.
o To detect errors
o To validate that what has been specified is what the
user actually wanted
Satisfied the needs of stakeholders.
Meets the requirements that guided its design and
development.
4. Testing Levels
Verification White Box RD
Unit Test Are we building the
system right ? Testing
Integration
Test
System
Test
Acceptance
Validation Black Box SQA
Test Are we building the
Testing
right system ?
5. Unit Testing (1/8)
• What
一個測試
案例只測 最小的測
試一件事 試單位
情
Unit
Test
測試案例
外部相依
之間相依
性為零
性為零
7. Unit Testing (3/8)
• Why
遵循介面 利用 Mock 使用 Mock
Object 達 模擬真實環境
Object 來
到相依層 模擬外部回
獨立開發 傳的資料
Unit
Test
Submit 的
回歸測試保護 改完成式 驗證提交代碼
程式碼包
就跑一次
括 UT
UT 吧!
Code
8. Unit Testing (4/9)
• Where (Test Scope)
1
1. invoke the method
Test Program Tested Object
2. verify the return value
2
1. invoke the method
Test Program Tested Object 2. status changed
3. verify the changed status
9. Unit Testing (5/9)
• Where (Test Scope)
3
1. invoke the method
Dependent
Test Program Tested Object Object
(Mock)
2. verify the return value
4
1. invoke the method
Dependent
Test Program Tested Object Object
(Mock)
3. verify the changed status
2. status changed
10. Unit Testing (6/9)
• Where (Test Scope)
5 1. notify to change the status (from external)
Test Program Tested Object
2. verify the changed status
6 1. notify to change the status (from external)
Dependent
Test Program Tested Object Object
(Mock)
2. verify the changed status
11. Unit Testing (7/9)
• Who
o Writing UT is the responsibility of RD not QA/QE.
設計物件的人員,才能知道物件該怎麼給外面使用
由外部使用物件的角度來設計測試案例
• Help to review the APIs
• Defining the APIs prototype is important. (Only one chance)
想要達到什麼需求,就是測試案例。
而物件的設計,只是為了滿足需求,需求即測試案例。
即 Production Code 只為了滿足測試程式上的測試案例。
12. Unit Testing (8/9)
• When
o Developing
外部需要使用物件,並對其執行結果有所預期時
o Modifying
Modified code due to bug fixed
Modified code due to refactor
o Bug fixing
Unexpected situation occurs
13. Unit Testing (9/9)
• Unit Testing should be "FIRST"
Repeatable
Self
Independent
Validation
FAST FIRST Timely