TDD - Agile

5,053
-1

Published on

Test driven development insight

Published in: Education, Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,053
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
305
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

TDD - Agile

  1. 1. TDD (JSAG)<br />Presented By : Harinder Singh Bedi<br />6 July 2011<br />
  2. 2. Agenda<br /><ul><li>What is TDD ?
  3. 3. Steps to start
  4. 4. Refactoring
  5. 5. TDD terminology
  6. 6. Benefits
  7. 7. JUnit
  8. 8. Mocktio
  9. 9. Continuous Integration</li></li></ul><li>Test Driven Development (TDD) or Test First Development is a Software Development technique and one of the key factors of Extreme Programming Methodology.<br />Test Driven Development<br />
  10. 10. Development Approaches<br /><ul><li>Ad hoc development
  11. 11. Writing pseudo code first
  12. 12. Model Driven Development (MDD)
  13. 13. Test Driven Development (TDD)</li></li></ul><li>What is TDD ?<br />TDD = Test First Development + Refactoring<br />
  14. 14. How Does TDD Help<br /><ul><li>Ensures that your design is clean by focusing on creation of operations that are callable and testable
  15. 15. Shortens the programming feedback loop
  16. 16. Provides detailed specification through tests
  17. 17. Provides concrete evidence that your software works
  18. 18. Supports evolutionary development.</li></li></ul><li>TDD says ..<br />When we have a new feature to implement, we initially often think, ok how should I implement this ?<br />But TDD says don't do it! <br />"In TDD, the greater emphasis is on the usage rather than implementation"<br />
  19. 19. Steps to start TDD<br />Analyze the requirements and write the list of tasks or features<br />Pick a task or feature<br />Brainstorm a list of tests for the task or feature<br />Review the tests list and pick a test<br />Write the test case<br />Run the test case and see it fails to compile<br />Write only enough code that the test case compiles<br />Run the test and see running the code fails<br />Write only enough code to just pass the test<br />Refactor the production code and eliminate duplication<br />Repeat <br />
  20. 20. When a bug is found ..<br />First create a test case to reveal the bug<br />Modify the production code so that the failed test passes <br />Finally run all the tests and make sure your bug is fixed and covered.<br />
  21. 21. Refactoring is one of the most important parts of TDD, which means you need to refine the code design as you add new tests.Refactoring should be done consistently as you increment the software, adding tests and production code.<br />Refactoring<br />
  22. 22. TDD terminology<br />Testcase : Function or method that tests one behavior of the code <br />Testsuite : Set of test cases, typically grouped by fixture. <br />Fixture : generated via a setUp() method and destroyed in tearDown(). <br />Assertion Function or macro allowing to compare the expected value against the actual one.<br />setUp() : It is a method of the Test Case class in jUnit that can be redefined in your Test class and used to create the execution environment for all test cases in the class.<br />
  23. 23. TDD terminology<br />Refactoring : is a source code manipulation to improving the design of the code, without altering its external behavior. <br />Unit : what is being tested, ranging from a single method to a set of classes. <br />Mock object an object implementing the same interface as, or sub classing a class of the production code, and exhibiting a deterministic behavior. <br />Red bar and green bar : comes from the graphical version of JUnit, where progression bar shows the execution of the tests, and goes from green to red when a test fails.<br />
  24. 24. TDD Benefits<br />Test Coverage : TDD does make sure that virtually every line is executed and tested.<br />Test Repeatability : Having the tests to back you up can give you the courage to make changes that would otherwise be too risky to make.<br />Documentation : The tests describe your understanding of how the code should behave. They also describe the API. Therefore, the tests are a form of documentation.<br />API Design : when you write tests first, you put yourself in the position of a user of your program's API.<br />
  25. 25. TDD Benefits<br />System Design: A module that is independently testable is a module that is decoupled from the rest of the system. <br />Reduced Debugging : When you move in the tiny little steps recommended by TDD, it is hardly ever necessary to use the debugger.<br />Confidence : If you observe a team of developers who are practicing TDD, you will notice that every pair of developer had their code working a minute ago.<br />
  26. 26. Testing libraries<br />Java - JUnit<br />Ruby – Test::Unit<br />Javascript – Test.More or JSUnit no clear standard<br />C++ - CPPUnit<br />PHP - PHPUnit<br />Python - PyUnit<br />
  27. 27. TDD frameworks<br />JUnit : It is the primary test tool for satisfying the first requirement for a Java test framework. <br />Tutorial Reference : harinder1637Share-dTDDCouse material<br />Mockito : is a Java-based framework for creating mock objects. It allows developers to create mocks based on classes or interfaces, specify behavior and return values for methods, and verify interactions.<br />Tutorial Reference : http://gojko.net/2009/10/23/mockito-in-six-easy-examples/<br />
  28. 28. Continuous integration<br />Continuous integration (CI) is a software engineering practice in which isolated changes are immediately tested and reported on when they are added to a larger code base. The goal of CI is to provide rapid feedback so that if a defect is introduced into the code base, it can be identified and corrected as soon as possible. <br />Continuous integration software tools can be used to automate the testing and build a document trail.<br />
  29. 29. Best Practices of CI<br /><ul><li>Automate the build
  30. 30. Create Tests to make the build self-testing
  31. 31. Everyone commits to the baseline every day
  32. 32. Every commit (to baseline) should be built
  33. 33. Everyone can see the results of the latest build
  34. 34. Automate deployment
  35. 35. Automation testing is absolute essential as the system grows e.g. selenium, fitnesse</li></li></ul><li><ul><li>Having a tester in the team from day 1 is a MUST
  36. 36. By the time developer is ready with a feature, Tester is also ready with scripts to break the feature
  37. 37. Testers should evaluate requirements and should actively participate with product team to do analysis</li></ul>TDD tests provide a way so that every developer machine can be tested. Also tests make the build self-testing.<br />
  38. 38. Software tools to support CI<br /><ul><li>Hudson – powerful software written in Java to automate build software, </li></ul> supports CVS, SVN, Git, Ant, Maven.<br /><ul><li> Bamboo -- toautomate build software.
  39. 39. BuildMaster -- proprietary application life cycle management and continuous </li></ul> integration tool by Inedo.<br />
  40. 40. Questions / Queries / Feedback ?<br />Send to feedback@nagarro.com<br />Thank You<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×