際際滷

際際滷Share a Scribd company logo
Automation Testing &
TDD
Nguy畛n Kh畉c Nh畉t
N畛i dung
 Ki畛m th畛
 Ki畛m th畛 t畛 季畛亀乙
 Ki畛m th畛 董n 厩畛
 TDD  Ph叩t tri畛n H動畛ng Ki畛m th畛
 Demo
CRISIS
Numbers:
4.4 million cars recalled
$7.7 Billions of $ loss.
Damage the brand
畉nh: Reuters
Numbers:
$17 Billions of $ loss.
Damage the brand
Galaxy Note 7 recall
Automation Testing & TDD
Do you know?
Software Bugs Cost U.S. Economy
$312 Billion
Annually
6
Source:http://insight.jbs.cam.ac.uk/2013/financial-content-cambridge-university-study-states-software-bugs-cost-economy-312-billion-per-year
Automation Testing & TDD
Ki畛m th畛
cng s畛m
cng t畛t
 N畉u c叩c bug
動畛c ph叩t hi畛n
cng mu畛n th狸 chi
ph鱈 s畉 cng cao
Ki畛m th畛
Mong mu畛n vs. Th畛c t畉
10
Requirement
Design
Desired
Implementation
Reality
testing
gap
Ai ch畛u tr叩ch nhi畛m cho ch畉t l動畛ng ph畉n
m畛m?
 Tester
 QA
 Developer
 ScrumMaster
 PM
 Product Manager
 Product Owner
 BA
 Customer?
11
Faster delivery, faster feedback
Time

Iteration
Process of testing
Test-related
learning
Test design
Test execution
Result
interpretation
13
C叩c chi畉n thu畉t ki畛m th畛
 Black-box (h畛p en)
 D畛a tr棚n thi畉t k畉 ch畛c nng c畛a h畛 th畛ng
 Kh担ng quan t但m 畉n n畛i b畛 b棚n trong t畛ng ch畛c nng
 Kh担ng ki畛m th畛 動畛c c叩c ch畛c nng 畉n
 White-box (h畛p tr畉ng)
 D畛a tr棚n thi畉t k畉 chi ti畉t b棚n trong c畛a ch畛c nng, ho畉c d畛a tr棚n code
 Kh担ng ph叩t hi畛n 動畛c c叩c ch畛c nng b畛 thi畉u
Black-box vs. White-box
Desired
Designed
Implemented
Black Box
White Box
Ki畛m th畛 t畛 季畛亀乙
T畛c 畛 ph叩t hnh ph畉n m畛m
Development Flow
Requirement
Analysis
UI Mocking
Customer
discussion
Design Draft
Design
Discussion
Code the
skeleton to
test the
design
Coding in
team
Refactoring
and
Refinement
Build the
increment
$
DevTeamPO
Collaboration:
Steps:
Artifacts:
As a super user,
I want to 
A
B
IDo
Interface IDo{
//TODO 
}
Class A{
//TODO 
}
Class B:IDo{
//TODO 
}
Interface IDo{
//TODO 
}
Class A{
method1(){
//Mr. A codes here
}
}
Class B:IDo{
method1(){
//Mrs. B codes here
}
}
Class C{
}
$
PO
Test (5)
Test (10)
Test (15)
Test (100)
Test (1000)
Automation Test
Ki畛m th畛 t畛 季畛亀乙
 Ki畛m th畛 t畛 季畛亀乙 (automated testing) l h狸nh th畛c s畛 d畛ng c叩c
c担ng c畛 畛 t畛 季畛亀乙 th畛c thi c叩c test case, kh叩c v畛i ki畛m th畛
th畛 c担ng (manual testing  do con ng動畛i th畛c hi畛n)
 L畛i 鱈ch c畛a ki畛m th畛 t畛 季畛亀乙:
 Tng t畛c 畛 ki畛m th畛
 Gi畉m chi ph鱈
 D畛 th畛c hi畛n ki畛m th畛 h畛i quy (regression testing)
 Ki畛m th畛 董n 厩畛 th動畛ng 動畛c ti畉n hnh d動畛i h狸nh th畛c t畛 季畛亀乙
 M畛t s畛 c担ng c畛 h畛 tr畛 ki畛m th畛 t畛 季畛亀乙 ph畛 bi畉n cho Java:
Junit, TestNG, JTest, Mockito
Unit Test 
Ki畛m th畛 董n 厩畛
C叩c m畛c ki畛m th畛
 D畛a vo 畛i t動畛ng 動畛c ki畛m th畛, c坦 th畛
chia thnh 4 m畛c 畛 ki畛m th畛 ph畛 bi畉n
nh動 sau:
 Ki畛m th畛 董n 厩畛 (Unit Testing)
 Ki畛m th畛 T鱈ch h畛p (Integration Testing)
 Ki畛m th畛 H畛 th畛ng (System Testing)
 Ki畛m th畛 Ng動畛i d湛ng/Ki畛m th畛 Ch畉p nh畉n
(User Testing/Acceptance Testing)
Ki畛m th畛 董n 厩畛
 Ki畛m th畛 董n 厩畛 (Unit Testing) l thao t叩c ki畛m th畛 動畛c th畛c
hi畛n tr棚n c叩c 董n 厩畛/thnh ph畉n nh畛 c畛a ch動董ng tr狸nh
 Ki畛m th畛 董n 厩畛 動畛c d湛ng 畛 ki畛m tra t鱈nh ch鱈nh x叩c c畛a c叩c
董n 厩畛 m達 ngu畛n nh畛 khi ch炭ng 動畛c th畛c thi 畛c l畉p
 M畛t 董n 厩畛 c坦 th畛 l m畛t kh畛i l畛nh, m畛t ph動董ng th畛c, m畛t l畛p,
m畛t module
 M畛t 董n 厩畛 th動畛ng l nh畛: bao g畛m 鱈t 畉u vo, 鱈t 畉u ra v
kh担ng qu叩 ph畛c t畉p
 董n 厩畛 th動畛ng 動畛c 叩p d畛ng ph畛 bi畉n l 畛 m畛c ph動董ng th畛c
 Ki畛m th畛 董n 厩畛 th動畛ng 動畛c th畛c hi畛n b畛i L畉p tr狸nh vi棚n
JUnit
 JUnit l m畛t Testing Framework 動畛c s畛 d畛ng cho ng担n ng畛
Java
 Website: https://junit.org
 Junit th動畛ng 動畛c t鱈ch h畛p s畉n trong c叩c IDE th担ng d畛ng nh動
Netbeans, Eclipse, IntelliJ IDEA
 Ngoi JUnit th狸 c坦 TestNG l m畛t Testing Framework th担ng
d畛ng cho Java
 C坦 th畛 s畛 d畛ng JUnit k畉t h畛p v畛i c叩c c担ng c畛 kh叩c nh動
Mockito, PowerMock, EvoSuite
Vi畉t test case trong Junit: V鱈 d畛
 Trong 坦:
 @Test 動畛c s畛 d畛ng 畛 khai b叩o m畛t ph動董ng th畛c test
 assertEquals d湛ng 畛 so s叩nh b畉ng 2 gi叩 tr畛
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class FirstJUnit5Tests {
@Test
void myFirstTest() {
assertEquals(2, 1 + 1);
}
}
M畛t l畛p Test c董 b畉n
class StandardTests {
@BeforeAll
static void initAll() {
}
@BeforeEach
void init() {
}
@Test
void succeedingTest() {
}
@Test
void failingTest() {
fail("a failing test");
}
...
@Test
@Disabled("for demonstration purposes")
void skippedTest() {
// not executed
}
@AfterEach
void tearDown() {
}
@AfterAll
static void tearDownAll() {
}
}
C叩c assertions
 assertEquals()
 assertTrue()
 assertFalse()
 assertNull()
 assertNotNull()
 assertThrows()
 assertTimeout()
 assertArrayEquals()
DEMO
Ki畛m th畛 董n 厩畛
TDD 
Test Driven Development
Test First v TDD
 Test First l m畛t c叩ch ti畉p c畉n m畛i so v畛i m担 h狸nh ph叩t tri畛n
ph畉n m畛m truy畛n th畛ng, trong 坦 vi畛c l畉p tr狸nh b畉t 畉u b畉ng
c叩ch vi畉t c叩c bi ki畛m th畛 tr動畛c khi b畉t tay vo vi畉t m達 ngu畛n
c畛a ch動董ng tr狸nh
 TDD (Test Driven Development) l m畛t quy tr狸nh l畉p tr狸nh, trong
坦 bao g畛m nhi畛u giai o畉n nh畛 l畉p i l畉p l畉i, m畛i giai o畉n bao
g畛m c叩c b動畛c:
 Vi畉t c叩c bi ki畛m th畛
 Vi畉t m達 ngu畛n
 T叩i c畉u tr炭c m達 ngu畛n.
V嘆ng th畛c thi c畛a TDD
 Vi畉t Test
 Fail b畛i v狸 ch動a c坦 m達 ngu畛n
 Th担ng th動畛ng c叩c IDE s畉 b叩o message mu
畛
 Vi畉t m達 ngu畛n
 Vi畉t m達 ngu畛n 畛 v動畛t qua test
 Th担ng th動畛ng c叩c IDE s畉 b叩o message mu
xanh
 T叩i c畉u tr炭c m達 ngu畛n
 Ch畛nh s畛a m達 ngu畛n 畛 t畛t h董n
 C畉n 畉m b畉o m達 ngu畛n v畉n v動畛t qua 動畛c
c叩c bi test
1. FAIL
2. PASS
3.
REFACTOR
Automation Testing & TDD
Ph但n lo畉i tam gi叩c
Gi叩 tr畛 c畛a
c畉nh a
Gi叩 tr畛 c畛a
c畉nh b
Gi叩 tr畛 c畛a
c畉nh c
Lo畉i tam gi叩c
2 2 2 tam gi叩c 畛u
2 2 3 tam gi叩c c但n
3 4 5 tam gi叩c th動畛ng
8 2 3 kh担ng ph畉i l tam gi叩c

More Related Content

Automation Testing & TDD

  • 2. N畛i dung Ki畛m th畛 Ki畛m th畛 t畛 季畛亀乙 Ki畛m th畛 董n 厩畛 TDD Ph叩t tri畛n H動畛ng Ki畛m th畛 Demo
  • 3. CRISIS Numbers: 4.4 million cars recalled $7.7 Billions of $ loss. Damage the brand
  • 4. 畉nh: Reuters Numbers: $17 Billions of $ loss. Damage the brand Galaxy Note 7 recall
  • 6. Do you know? Software Bugs Cost U.S. Economy $312 Billion Annually 6 Source:http://insight.jbs.cam.ac.uk/2013/financial-content-cambridge-university-study-states-software-bugs-cost-economy-312-billion-per-year
  • 8. Ki畛m th畛 cng s畛m cng t畛t N畉u c叩c bug 動畛c ph叩t hi畛n cng mu畛n th狸 chi ph鱈 s畉 cng cao
  • 10. Mong mu畛n vs. Th畛c t畉 10 Requirement Design Desired Implementation Reality testing gap
  • 11. Ai ch畛u tr叩ch nhi畛m cho ch畉t l動畛ng ph畉n m畛m? Tester QA Developer ScrumMaster PM Product Manager Product Owner BA Customer? 11
  • 12. Faster delivery, faster feedback Time Iteration
  • 13. Process of testing Test-related learning Test design Test execution Result interpretation 13
  • 14. C叩c chi畉n thu畉t ki畛m th畛 Black-box (h畛p en) D畛a tr棚n thi畉t k畉 ch畛c nng c畛a h畛 th畛ng Kh担ng quan t但m 畉n n畛i b畛 b棚n trong t畛ng ch畛c nng Kh担ng ki畛m th畛 動畛c c叩c ch畛c nng 畉n White-box (h畛p tr畉ng) D畛a tr棚n thi畉t k畉 chi ti畉t b棚n trong c畛a ch畛c nng, ho畉c d畛a tr棚n code Kh担ng ph叩t hi畛n 動畛c c叩c ch畛c nng b畛 thi畉u
  • 16. Ki畛m th畛 t畛 季畛亀乙
  • 17. T畛c 畛 ph叩t hnh ph畉n m畛m
  • 18. Development Flow Requirement Analysis UI Mocking Customer discussion Design Draft Design Discussion Code the skeleton to test the design Coding in team Refactoring and Refinement Build the increment $ DevTeamPO Collaboration: Steps: Artifacts: As a super user, I want to A B IDo Interface IDo{ //TODO } Class A{ //TODO } Class B:IDo{ //TODO } Interface IDo{ //TODO } Class A{ method1(){ //Mr. A codes here } } Class B:IDo{ method1(){ //Mrs. B codes here } } Class C{ } $ PO
  • 24. Ki畛m th畛 t畛 季畛亀乙 Ki畛m th畛 t畛 季畛亀乙 (automated testing) l h狸nh th畛c s畛 d畛ng c叩c c担ng c畛 畛 t畛 季畛亀乙 th畛c thi c叩c test case, kh叩c v畛i ki畛m th畛 th畛 c担ng (manual testing do con ng動畛i th畛c hi畛n) L畛i 鱈ch c畛a ki畛m th畛 t畛 季畛亀乙: Tng t畛c 畛 ki畛m th畛 Gi畉m chi ph鱈 D畛 th畛c hi畛n ki畛m th畛 h畛i quy (regression testing) Ki畛m th畛 董n 厩畛 th動畛ng 動畛c ti畉n hnh d動畛i h狸nh th畛c t畛 季畛亀乙 M畛t s畛 c担ng c畛 h畛 tr畛 ki畛m th畛 t畛 季畛亀乙 ph畛 bi畉n cho Java: Junit, TestNG, JTest, Mockito
  • 25. Unit Test Ki畛m th畛 董n 厩畛
  • 26. C叩c m畛c ki畛m th畛 D畛a vo 畛i t動畛ng 動畛c ki畛m th畛, c坦 th畛 chia thnh 4 m畛c 畛 ki畛m th畛 ph畛 bi畉n nh動 sau: Ki畛m th畛 董n 厩畛 (Unit Testing) Ki畛m th畛 T鱈ch h畛p (Integration Testing) Ki畛m th畛 H畛 th畛ng (System Testing) Ki畛m th畛 Ng動畛i d湛ng/Ki畛m th畛 Ch畉p nh畉n (User Testing/Acceptance Testing)
  • 27. Ki畛m th畛 董n 厩畛 Ki畛m th畛 董n 厩畛 (Unit Testing) l thao t叩c ki畛m th畛 動畛c th畛c hi畛n tr棚n c叩c 董n 厩畛/thnh ph畉n nh畛 c畛a ch動董ng tr狸nh Ki畛m th畛 董n 厩畛 動畛c d湛ng 畛 ki畛m tra t鱈nh ch鱈nh x叩c c畛a c叩c 董n 厩畛 m達 ngu畛n nh畛 khi ch炭ng 動畛c th畛c thi 畛c l畉p M畛t 董n 厩畛 c坦 th畛 l m畛t kh畛i l畛nh, m畛t ph動董ng th畛c, m畛t l畛p, m畛t module M畛t 董n 厩畛 th動畛ng l nh畛: bao g畛m 鱈t 畉u vo, 鱈t 畉u ra v kh担ng qu叩 ph畛c t畉p 董n 厩畛 th動畛ng 動畛c 叩p d畛ng ph畛 bi畉n l 畛 m畛c ph動董ng th畛c Ki畛m th畛 董n 厩畛 th動畛ng 動畛c th畛c hi畛n b畛i L畉p tr狸nh vi棚n
  • 28. JUnit JUnit l m畛t Testing Framework 動畛c s畛 d畛ng cho ng担n ng畛 Java Website: https://junit.org Junit th動畛ng 動畛c t鱈ch h畛p s畉n trong c叩c IDE th担ng d畛ng nh動 Netbeans, Eclipse, IntelliJ IDEA Ngoi JUnit th狸 c坦 TestNG l m畛t Testing Framework th担ng d畛ng cho Java C坦 th畛 s畛 d畛ng JUnit k畉t h畛p v畛i c叩c c担ng c畛 kh叩c nh動 Mockito, PowerMock, EvoSuite
  • 29. Vi畉t test case trong Junit: V鱈 d畛 Trong 坦: @Test 動畛c s畛 d畛ng 畛 khai b叩o m畛t ph動董ng th畛c test assertEquals d湛ng 畛 so s叩nh b畉ng 2 gi叩 tr畛 import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class FirstJUnit5Tests { @Test void myFirstTest() { assertEquals(2, 1 + 1); } }
  • 30. M畛t l畛p Test c董 b畉n class StandardTests { @BeforeAll static void initAll() { } @BeforeEach void init() { } @Test void succeedingTest() { } @Test void failingTest() { fail("a failing test"); } ... @Test @Disabled("for demonstration purposes") void skippedTest() { // not executed } @AfterEach void tearDown() { } @AfterAll static void tearDownAll() { } }
  • 31. C叩c assertions assertEquals() assertTrue() assertFalse() assertNull() assertNotNull() assertThrows() assertTimeout() assertArrayEquals()
  • 33. TDD Test Driven Development
  • 34. Test First v TDD Test First l m畛t c叩ch ti畉p c畉n m畛i so v畛i m担 h狸nh ph叩t tri畛n ph畉n m畛m truy畛n th畛ng, trong 坦 vi畛c l畉p tr狸nh b畉t 畉u b畉ng c叩ch vi畉t c叩c bi ki畛m th畛 tr動畛c khi b畉t tay vo vi畉t m達 ngu畛n c畛a ch動董ng tr狸nh TDD (Test Driven Development) l m畛t quy tr狸nh l畉p tr狸nh, trong 坦 bao g畛m nhi畛u giai o畉n nh畛 l畉p i l畉p l畉i, m畛i giai o畉n bao g畛m c叩c b動畛c: Vi畉t c叩c bi ki畛m th畛 Vi畉t m達 ngu畛n T叩i c畉u tr炭c m達 ngu畛n.
  • 35. V嘆ng th畛c thi c畛a TDD Vi畉t Test Fail b畛i v狸 ch動a c坦 m達 ngu畛n Th担ng th動畛ng c叩c IDE s畉 b叩o message mu 畛 Vi畉t m達 ngu畛n Vi畉t m達 ngu畛n 畛 v動畛t qua test Th担ng th動畛ng c叩c IDE s畉 b叩o message mu xanh T叩i c畉u tr炭c m達 ngu畛n Ch畛nh s畛a m達 ngu畛n 畛 t畛t h董n C畉n 畉m b畉o m達 ngu畛n v畉n v動畛t qua 動畛c c叩c bi test 1. FAIL 2. PASS 3. REFACTOR
  • 37. Ph但n lo畉i tam gi叩c Gi叩 tr畛 c畛a c畉nh a Gi叩 tr畛 c畛a c畉nh b Gi叩 tr畛 c畛a c畉nh c Lo畉i tam gi叩c 2 2 2 tam gi叩c 畛u 2 2 3 tam gi叩c c但n 3 4 5 tam gi叩c th動畛ng 8 2 3 kh担ng ph畉i l tam gi叩c