Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Tech talks #1- Unit testing and TDD

3,040 views

Published on

Presentation at FPT Aptech's TechTalks series

Published in: Education, Technology
  • Be the first to comment

Tech talks #1- Unit testing and TDD

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

×