38
Test Driven Development LE ANH APOLLO13.VN

TDD - Test Driven Development

Embed Size (px)

Citation preview

Page 1: TDD - Test Driven Development

Test Driven DevelopmentLE ANHAPOLLO13.VN

Page 2: TDD - Test Driven Development

Outline Overview about TDD Why use TDD ? How to do ? TDD by Example Common mistakes in TDD When we use TDD ? Q&A

Page 3: TDD - Test Driven Development

Overview about TDDTDD stand for Test Driven Development (Test Driven Design)

Page 4: TDD - Test Driven Development

Overview about TDDRegardless of the programming language

Page 5: TDD - Test Driven Development

Overview about TDDTDD is a strong methodology

Without TDD TDD

Page 6: TDD - Test Driven Development

Why use TDD ?

Clean code

Page 7: TDD - Test Driven Development

Why use TDD ?

Without TDD Prevent bugs by TDD

Page 8: TDD - Test Driven Development

Why use TDD ?

Design document

Page 9: TDD - Test Driven Development

Why use TDD ?

Maintainable, flexible, easily extensible

Page 10: TDD - Test Driven Development

Why use TDD ?

TDD change your mindset a bout programming & testing. You can become a better programmer

Page 11: TDD - Test Driven Development

How to do TDD?

Do it in baby stepsIs TDD Difficult ?

Page 12: TDD - Test Driven Development

How to do TDD?

Mantra of TDD is “Red/Green/Refactor”

Page 13: TDD - Test Driven Development

How to do TDD?

Red text is 3C rule. They help raise your idea

Page 14: TDD - Test Driven Development

How to do TDD? We have a user story, use 3C rule to make your idea (baby

requirement)

Allow user input a string to set the display name when he login. Max length of string is 125 characters

Page 15: TDD - Test Driven Development

How to do TDD? String can contain special characters ? What kind of special characters (!@#$%^&...) ? String can contain space ? String can contain number ? Min length of string ? String can not contain select, delete, update

because of SQL injection String can be duplicate ?

Note : Don’t think the requirement is very simple therefore we don’t need to confirm with PO. Confirmation is a way to prevent bugs

Page 16: TDD - Test Driven Development

TDD by examples Example 1: write a method that reverse last 2

characters of string. If null return null, if empty return empty, if

length of string equal 1 return itself Ex: “A” “A”, “” “”, null null, “AB” “BA”,

“RAIN” “RANI”

Page 17: TDD - Test Driven Development

TDD by examples Create first test case

Page 18: TDD - Test Driven Development

TDD by examples Can not compile because StringHelper class is not created

Page 19: TDD - Test Driven Development

TDD by examples After StringHelper class is created, run ALL TEST CASE to

see they(or one of them) fail

Page 20: TDD - Test Driven Development

TDD by examples Make a litte change to pass this test cases

Question : Who has a better implementation ?

Page 21: TDD - Test Driven Development

TDD by examples Run ALL TEST CASES to see they pass

Page 22: TDD - Test Driven Development

TDD by examples We have just finished a baby step of TDD cycle. Repeat it

again.

Page 23: TDD - Test Driven Development

TDD by examples After StringHelper class is created, run ALL TEST CASE to

see they(or one of them) fail

Page 24: TDD - Test Driven Development

TDD by examples Refactor code to pass this test case

Page 25: TDD - Test Driven Development

TDD by examples Run all test cases to see they pass

Page 26: TDD - Test Driven Development

TDD by examples Refactor test code if necessary

Page 27: TDD - Test Driven Development

TDD by examples Add new test case

Page 28: TDD - Test Driven Development

TDD by examples After StringHelper class is created, run ALL TEST CASE to

see they(or one of them) fail

Page 29: TDD - Test Driven Development

TDD by examples Refractor code to pass the test case

Page 30: TDD - Test Driven Development

TDD by examples Run all test cases to see they pass

Page 31: TDD - Test Driven Development

TDD by examples Add new test case, this test case will be pass without any

changes

Page 32: TDD - Test Driven Development

TDD by examples Add new test case, this test case will be fail

Page 33: TDD - Test Driven Development

TDD by examples Refactor code

Page 34: TDD - Test Driven Development

TDD by examples Run all test cases, if they pass and you don’t have any test

case. The TDD cycle is completed. Refactor code if necessary

Page 35: TDD - Test Driven Development

TDD by examples

Example 2: Refer the below link

http://technologyconversations.com/2013/12/20/test-driven-development-tdd-example-walkthrough/

Page 36: TDD - Test Driven Development

Common mistakes in TDD

Page 37: TDD - Test Driven Development

Summary

Page 38: TDD - Test Driven Development

Q&A What is the position of tester in agile test

(TDD) ? What is BDD/ATDD ? What are the skill of tester, developer in

scrum ? When we use TDD ? Is TDD dead ? Some questions from audiences…..