tech talks #1- unit testing and tdd

24
TechTalks #1 TechTalks #1 Unit Testing and Test-Driven Developmen t Duong Trong Tan [email protected] Hanoi, 9- 2011

Upload: duong-trong-tan

Post on 16-Apr-2017

2.871 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Tech talks #1- Unit testing and TDD

TechTalks #1TechTalks #1

Unit Testing and Test-Driven Development

Duong Trong [email protected], 9- 2011

Page 2: Tech talks #1- Unit testing and TDD

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

Page 3: Tech talks #1- Unit testing and TDD

Unit Testing and Test-Driven Development 3

CRISIS

Numbers:4.4 million cars recalledBillions of $ loss.Damage the brand

Page 4: Tech talks #1- Unit testing and TDD

Desire vs. Reality

Unit Testing and Test-Driven Development 4

Requirement\Design

Desired

Implementation

Reality

testing

gap

Page 5: Tech talks #1- Unit testing and TDD

Why testing?

0 Ensuring QUALITY

0 Managing RISKS

0 Optimizing Return-On-Investment (ROI)

0 Professionalism

Unit Testing and Test-Driven Development 5

Page 6: Tech talks #1- Unit testing and TDD

Typical Production model

Unit Testing and Test-Driven Development 6

Page 7: Tech talks #1- Unit testing and TDD

Bug cost

Unit Testing and Test-Driven Development 7

Page 8: Tech talks #1- Unit testing and TDD

Balancing

Unit Testing and Test-Driven Development 8

GOOD

FASTCHEAP

Page 9: Tech talks #1- Unit testing and TDD

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

Page 10: Tech talks #1- Unit testing and TDD

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/

Page 11: Tech talks #1- Unit testing and TDD

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

Page 12: Tech talks #1- Unit testing and TDD

Suggested TDD

Unit Testing and Test-Driven Development 12

Page 13: Tech talks #1- Unit testing and TDD

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

Page 14: Tech talks #1- Unit testing and TDD

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

Page 15: Tech talks #1- Unit testing and TDD

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)

Page 16: Tech talks #1- Unit testing and TDD

Red-Green-Blue model

Unit Testing and Test-Driven Development 16

Page 17: Tech talks #1- Unit testing and TDD

Refactor to Clean Code

0Readable

0Maintainable

0Changeable

Unit Testing and Test-Driven Development 17

Page 18: Tech talks #1- Unit testing and TDD

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

Page 19: Tech talks #1- Unit testing and TDD

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

Page 20: Tech talks #1- Unit testing and TDD

Supporting system: CI

Unit Testing and Test-Driven Development 20

Page 21: Tech talks #1- Unit testing and TDD

Q&A

Unit Testing and Test-Driven Development 21

Page 22: Tech talks #1- Unit testing and TDD

Further reading

Unit Testing and Test-Driven Development 22

Page 23: Tech talks #1- Unit testing and TDD

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

Page 24: Tech talks #1- Unit testing and TDD

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]