Date post: | 16-Apr-2017 |
Category: |
Education |
Upload: | duong-trong-tan |
View: | 2,869 times |
Download: | 1 times |
TechTalks #1TechTalks #1
Unit Testing and Test-Driven Development
Duong Trong [email protected], 9- 2011
Objectives
0 Why testing?
0 Introduction to unit testing
0 Unit testing in Java with JUnit
0 What is Test-Driven Development?
0 How can TDD improve quality?
0 TDD practices and guidelines.
Unit Testing and Test-Driven Development 2
Unit Testing and Test-Driven Development 3
CRISIS
Numbers:4.4 million cars recalledBillions of $ loss.Damage the brand
Desire vs. Reality
Unit Testing and Test-Driven Development 4
Requirement\Design
Desired
Implementation
Reality
testing
gap
Why testing?
0 Ensuring QUALITY
0 Managing RISKS
0 Optimizing Return-On-Investment (ROI)
0 Professionalism
Unit Testing and Test-Driven Development 5
Typical Production model
Unit Testing and Test-Driven Development 6
Bug cost
Unit Testing and Test-Driven Development 7
Balancing
Unit Testing and Test-Driven Development 8
GOOD
FASTCHEAP
Testing level0 Unit testing
0 On individual unit of source code (function, class, etc.)0 Smallest testable part0 Developer testing
0 Integration testing0 On groups of modules
0 System testing0 On complete integrated system
Unit Testing and Test-Driven Development 9
JUnit
0 Unit testing automation framework for Java
0 Can do integration test
0 Integrated in IDEs (Eclipse, NetBeans, IntelliJ, etc.)
0 Must have tool for Java developers
Unit Testing and Test-Driven Development 10
http://www.junit.org/
Test-Driven Development0 You don’t start programming until you have designed
your tests!0 Strategy
0 Make it Fail0No code without a failing test
0 Make it Work0As simply as possible
0 Make it Better0Refactor(code, design, test, documentation)
0 Believe in testing
Unit Testing and Test-Driven Development 11
Suggested TDD
Unit Testing and Test-Driven Development 12
Thinking changed
0 Design or code must be TESTABLE
0 “Error Message” is a good news
0 Courage
0 Simple
0 Agile
Unit Testing and Test-Driven Development 13
How to do TDD0 Design
0 Use [simple] design , figure out what to do0 [Then .. create the skeleton first]
0 Test0 Write test that reflect the design0 All tests should FAIL
0 Implement0 Write the code
0 Test0 All tests should PASS
Unit Testing and Test-Driven Development 14
TDD live demo
Unit Testing and Test-Driven Development 15
0 Application: simplified Calculator
0 Language: Java0 Tools used:
0 NetBeans 70 JUnit0 Task board (Excel)0 Whiteboard (for simple
design)
Red-Green-Blue model
Unit Testing and Test-Driven Development 16
Refactor to Clean Code
0Readable
0Maintainable
0Changeable
Unit Testing and Test-Driven Development 17
Acceptance Test-Driven Development
Unit Testing and Test-Driven Development 18
RequirementAutomated Acceptance
Tests TDD
Definition Of
Done
ATDD: team collaboration, a kind of cross-functionality
Acceptance TDD (ATDD)
3D strategy0 Discuss in requirement workshop
0 To make tests library0 Develop in concurrence
0 To create more Passed features0 Deliver for acceptance
0 To meet DONE definition, accepted by users
19Unit Testing and Test-Driven Development
Supporting system: CI
Unit Testing and Test-Driven Development 20
Q&A
Unit Testing and Test-Driven Development 21
Further reading
Unit Testing and Test-Driven Development 22
Tools0 JUnit: http://junit.org 0 FitNesse: http://fitnesse.org/ 0 RoBotFramework: http://code.google.com/p/
robotframework/ 0 Hudson CI: http://hudson-ci.org/ 0 SVN: http://subversion.tigris.org/
Unit Testing and Test-Driven Development 23
Unit Testing and Test-Driven Development 24
Thank you!
Meet Tấn DT:
•TechTalks•HanoiScrum.net•Slideshare.net/duongtrongtan•Facebook: Duong Trong Tan•[email protected]