TechTalks #1 Unit Testing and Test-Driven Development Duong Trong Tan [email_address] Hanoi, 9- 2011
Objectives Why testing? Introduction to unit testing Unit testing in Java with JUnit What is Test-Driven Development? How can TDD improve quality? TDD practices and guidelines. Unit Testing and Test-Driven Development
Unit Testing and Test-Driven Development CRISIS Numbers: 4.4 million  cars recalled Billions of $ loss. Damage the brand
Desire vs. Reality Unit Testing and Test-Driven Development gap Requirement \Design Desired Implementation Reality testing
Why testing? Ensuring  QUALITY Managing RISKS Optimizing Return-On-Investment (ROI) Professionalism Unit Testing and Test-Driven Development
Typical Production model Unit Testing and Test-Driven Development
Bug cost Unit Testing and Test-Driven Development
Balancing Unit Testing and Test-Driven Development GOOD FAST CHEAP
Testing level Unit testing On individual unit of source code (function, class, etc.) Smallest testable part Developer testing Integration testing On groups of modules System testing On complete integrated system Unit Testing and Test-Driven Development
JUnit Unit testing automation framework for Java Can do integration test Integrated in IDEs (Eclipse, NetBeans, IntelliJ, etc.) Must have  tool for Java developers Unit Testing and Test-Driven Development http://www.junit.org/
Test-Driven Development You don’t  start  programming until you have designed your tests! Strategy Make it Fail No code without a failing test Make it Work As simply as possible Make it Better Refactor(code, design, test, documentation) Believe in testing Unit Testing and Test-Driven Development
Suggested TDD Unit Testing and Test-Driven Development
Thinking changed Design or code must be  TESTABLE “ Error Message ” is a  good  news Courage Simple Agile Unit Testing and Test-Driven Development
How to do TDD Design Use [simple] design , figure out what to do [Then .. create the skeleton first] Test Write test that reflect the design All tests should  FAIL Implement Write the code Test All tests should  PASS Unit Testing and Test-Driven Development
TDD live demo Application: simplified Calculator Language: Java Tools used: NetBeans 7 JUnit Task board (Excel) Whiteboard (for simple design) Unit Testing and Test-Driven Development
Red-Green-Blue model Unit Testing and Test-Driven Development
Refactor to Clean Code Readable Maintainable Changeable Unit Testing and Test-Driven Development
Acceptance Test-Driven Development Unit Testing and Test-Driven Development ATDD: team collaboration, a kind of cross-functionality Requirement Automated  Acceptance  Tests TDD Definition  Of  Done
Acceptance TDD (ATDD) 3D strategy D iscuss in requirement workshop To make tests library D evelop in concurrence To create more Passed features D eliver for acceptance To meet DONE definition, accepted by users Unit Testing and Test-Driven Development
Supporting system: CI Unit Testing and Test-Driven Development
Q&A Unit Testing and Test-Driven Development
Further reading Unit Testing and Test-Driven Development
Tools JUnit :  http://junit.org   FitNesse :  http://fitnesse.org /   RoBotFramework:  http ://code.google.com/p/robotframework /   Hudson CI :  http://hudson-ci.org /   SVN :  http://subversion.tigris.org /   Unit Testing and Test-Driven Development
Unit Testing and Test-Driven Development Thank you! Meet Tấn DT: TechTalks HanoiScrum.net Slideshare.net/duongtrongtan Facebook: Duong  Trong Tan [email_address]

Tech talks #1- Unit testing and TDD

  • 1.
    TechTalks #1 UnitTesting and Test-Driven Development Duong Trong Tan [email_address] Hanoi, 9- 2011
  • 2.
    Objectives Why testing?Introduction to unit testing Unit testing in Java with JUnit What is Test-Driven Development? How can TDD improve quality? TDD practices and guidelines. Unit Testing and Test-Driven Development
  • 3.
    Unit Testing andTest-Driven Development CRISIS Numbers: 4.4 million cars recalled Billions of $ loss. Damage the brand
  • 4.
    Desire vs. RealityUnit Testing and Test-Driven Development gap Requirement \Design Desired Implementation Reality testing
  • 5.
    Why testing? Ensuring QUALITY Managing RISKS Optimizing Return-On-Investment (ROI) Professionalism Unit Testing and Test-Driven Development
  • 6.
    Typical Production modelUnit Testing and Test-Driven Development
  • 7.
    Bug cost UnitTesting and Test-Driven Development
  • 8.
    Balancing Unit Testingand Test-Driven Development GOOD FAST CHEAP
  • 9.
    Testing level Unittesting On individual unit of source code (function, class, etc.) Smallest testable part Developer testing Integration testing On groups of modules System testing On complete integrated system Unit Testing and Test-Driven Development
  • 10.
    JUnit Unit testingautomation framework for Java Can do integration test Integrated in IDEs (Eclipse, NetBeans, IntelliJ, etc.) Must have tool for Java developers Unit Testing and Test-Driven Development http://www.junit.org/
  • 11.
    Test-Driven Development Youdon’t start programming until you have designed your tests! Strategy Make it Fail No code without a failing test Make it Work As simply as possible Make it Better Refactor(code, design, test, documentation) Believe in testing Unit Testing and Test-Driven Development
  • 12.
    Suggested TDD UnitTesting and Test-Driven Development
  • 13.
    Thinking changed Designor code must be TESTABLE “ Error Message ” is a good news Courage Simple Agile Unit Testing and Test-Driven Development
  • 14.
    How to doTDD Design Use [simple] design , figure out what to do [Then .. create the skeleton first] Test Write test that reflect the design All tests should FAIL Implement Write the code Test All tests should PASS Unit Testing and Test-Driven Development
  • 15.
    TDD live demoApplication: simplified Calculator Language: Java Tools used: NetBeans 7 JUnit Task board (Excel) Whiteboard (for simple design) Unit Testing and Test-Driven Development
  • 16.
    Red-Green-Blue model UnitTesting and Test-Driven Development
  • 17.
    Refactor to CleanCode Readable Maintainable Changeable Unit Testing and Test-Driven Development
  • 18.
    Acceptance Test-Driven DevelopmentUnit Testing and Test-Driven Development ATDD: team collaboration, a kind of cross-functionality Requirement Automated Acceptance Tests TDD Definition Of Done
  • 19.
    Acceptance TDD (ATDD)3D strategy D iscuss in requirement workshop To make tests library D evelop in concurrence To create more Passed features D eliver for acceptance To meet DONE definition, accepted by users Unit Testing and Test-Driven Development
  • 20.
    Supporting system: CIUnit Testing and Test-Driven Development
  • 21.
    Q&A Unit Testingand Test-Driven Development
  • 22.
    Further reading UnitTesting and Test-Driven Development
  • 23.
    Tools JUnit : http://junit.org FitNesse : http://fitnesse.org / RoBotFramework: http ://code.google.com/p/robotframework / Hudson CI : http://hudson-ci.org / SVN : http://subversion.tigris.org / Unit Testing and Test-Driven Development
  • 24.
    Unit Testing andTest-Driven Development Thank you! Meet Tấn DT: TechTalks HanoiScrum.net Slideshare.net/duongtrongtan Facebook: Duong Trong Tan [email_address]

Editor's Notes

  • #3 I don’t want to frustrate you by bunch of testing terms. Just focus on thinking, process and how-tos.
  • #4 Global: 4.4 million cars recalled (http://wsws.org/articles/2010/feb2010/toyo-f12.shtml ) In the first quarter of 2009, the company posted a $7.7 billion loss. The estimated loss for Toyota in the current financial year, calculated before the expansion of the recall process in January, is $5.5 billion. http://parttimembadegree.com/business-school-cases/toyota-recalls-pr-management-crisis/ http://en.wikipedia.org/wiki/2009%E2%80%932011_Toyota_vehicle_recalls VN: “mua toy cho nó lành” – lost
  • #6 For ROI optimization, see the analysis of Rex Black on Managing the Testing Process: Practical Tools and Techniques for Managing Hardware and Software Testing
  • #8 In conclusion: Test a.s.a.p Testing is responsibilities of all including developers.
  • #12 Introduced in XP
  • #13 Design (simple) first => draft solution => Design criteria: testable
  • #17 Refactor, clean code frequently
  • #20 What is acceptance test? fist