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.

Test Driven Development


Published on

An introduction to TDD methodology that dispells some myths about unit testing in general.

Published in: Technology, Education
  • thanks ,great video i like
    Are you sure you want to  Yes  No
    Your message goes here

Test Driven Development

  1. 1. Test-Driven Development by John Blanco
  2. 2. The process of designing software by writing a validating client before the code. What is Test-Driven Development (TDD)? Maintaining an evolving set of unit tests that continuously validate the correctness (or not) of your code. What is Automated Unit Testing?
  3. 3. Automated Unit Testing != Test-Driven Development TDD is a way of thinking about your code, but it doesn’t require unit testing. That being said, you should write them if you can. Agile processes adapt to change. Unit tests help to manage change in our code. Unit Testing is a key component of the Agile Methodology
  4. 4. Dispelling Unit Testing Myths
  5. 5. No. Writing unit tests is an investment towards time savings over the lifetime of the project. Myth #1: Won’t writing unit tests double by development time? <ul><li>We won’t need to constantly validate our code each time we make changes. </li></ul><ul><li>Finding the bugs early means far less time fixing them later. </li></ul><ul><li>If our unit tests are good, we won’t need to spend hours or days tracking down bugs in the most fundamental layers of our code. </li></ul>
  6. 6. No. Unit tests are not parallel to your code like documentation. You will be driving your code with them. Myth #2: Won’t all my unit tests just get out of date? <ul><li>TDD is a programming paradigm. </li></ul><ul><li>Unit tests are not an artifact of your code. They represent how you write it! </li></ul><ul><li>However, if you don’t appreciate unit testing, they likely will not be worth the time to create. </li></ul>
  7. 7. No. The client is paying for clean, correct code. Unit testing is the means to that end. Myth #3: Won’t the client refuse to pay for it? <ul><li>Do they pay us to test our code? </li></ul><ul><li>Do they pay us to use design patterns? </li></ul><ul><li>Do they pay us to use UML? </li></ul>
  8. 8. xUnit is the framework for automating our unit tests. Implementations exist for C++, C#, Java, PHP, Ruby, Python, Perl, Prolog, LISP, … and Flex! Created by Erich Gamma, member of the GoF and co-author of Eclipse JDT. Introducing xUnit!
  9. 9. FlexUnit is the Flex implementation of xUnit. FlexUnit <ul><li>Tests you will be performing on your code: </li></ul><ul><li>assertEquals() </li></ul><ul><li>assertTrue() </li></ul><ul><li>assertNotUndefined() </li></ul><ul><li>assertStrictlyEquals() </li></ul><ul><li>… </li></ul>
  10. 10. Don’t worry. Chances are, you’re already writing unit tests! Whoa! Whoa! Hold On -- This Seems Excessive!
  11. 11. <mx:Application creationComplete=“onCreationComplete()”> <mx:Script> private function onCreationComplete():void { // DEVELOPMENT ONLY - REMOVE LATER var htmlMaker:MyHTMLMaker = new MyHTMLMaker(); htmlMaker.startTag(“b”); htmlMaker.addContent(“My bold text!!!”); htmlMaker.endTag(); trace(“RESULT: ” + htmlMaker.toString()); } </mx:Script> . . . </mx:Application> Ever Write Code Like This…And Then Delete It Afterwards?
  12. 12. Fool! The problem is that you’re not anticipating CHANGE. When that happens, you will need to modify and test your code all over again. What if we kept that test? Yes! And then once I verify it’s working, I remove it. So?
  13. 13. <ul><li>There are two ways we can organize our unit tests: </li></ul><ul><li>Inside the project </li></ul><ul><li>Outside the project </li></ul><ul><li>My personal preference is outside of the project. Here’s why: </li></ul><ul><li>Keeps our code and unit tests physically separate. </li></ul><ul><li>Avoids the double-build conundrum. </li></ul><ul><li>Allows us to close the unit test project when desirable. </li></ul><ul><li>Allows us to run tests against projects in multiple locations. </li></ul>Setting Up Your Project For TDD Reference:
  14. 14. <ul><li>Create a Flex or AIR project. (e.g., twitterme) </li></ul><ul><li>Create a Flex or AIR unit testing project. (e.g., twitterme-tests) </li></ul><ul><li>Add twitterme/src to the source path of twitterme-tests. </li></ul><ul><li>Add a boilerplate TestRunner application to twitterme-tests. </li></ul><ul><li>Add flexunit.swc to twitterme-tests/libs. </li></ul>Setting Up Your Project For TDD References:
  15. 15. Working Session
  16. 16. Wait! We Need a Change!
  17. 17. What Have We Accomplished?
  18. 18. Gain #1: We have a clean, stable piece of code <ul><li>We know the client code will be easy to use, because we drove the code based on the client itself! </li></ul><ul><li>We have tested the code as thoroughly as we can using unit tests. </li></ul><ul><li>We have kept the unit tests as an artifact of the coding effort so that we can continually re-run the tests as needed. </li></ul><ul><li>Code usage is already documented for our customers! </li></ul>
  19. 19. Gain #2: We will feel confident making changes to the code <ul><li>If we make a change to this code, we can re-run the unit tests to verify if the code is still functionally correct - instantly! </li></ul><ul><li>We don’t have to fear the major changes that will likely be made later. </li></ul>Because what is the one constant in software development? CHANGE.
  20. 20. <ul><li>dpuint offers some enhancements over FlexUnit that you might find valuable. The key differences are: </li></ul><ul><li>Better asynchronous support </li></ul><ul><li>Sequencing tests </li></ul><ul><li>Cairngorn tests </li></ul><ul><li>Highly recommended if you want to test UI. </li></ul>A Newer Flex Testing Framework: dpuint
  21. 21. Questions?