Test Driven Development

  • 1,143 views
Uploaded on

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

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

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • thanks ,great video i like
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
1,143
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
65
Comments
1
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Test-Driven Development by John Blanco
  • 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. 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. Dispelling Unit Testing Myths
  • 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?
    • We won’t need to constantly validate our code each time we make changes.
    • Finding the bugs early means far less time fixing them later.
    • 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.
  • 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?
    • TDD is a programming paradigm.
    • Unit tests are not an artifact of your code. They represent how you write it!
    • However, if you don’t appreciate unit testing, they likely will not be worth the time to create.
  • 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?
    • Do they pay us to test our code?
    • Do they pay us to use design patterns?
    • Do they pay us to use UML?
  • 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. FlexUnit is the Flex implementation of xUnit. FlexUnit
    • Tests you will be performing on your code:
    • assertEquals()
    • assertTrue()
    • assertNotUndefined()
    • assertStrictlyEquals()
  • 10. Don’t worry. Chances are, you’re already writing unit tests! Whoa! Whoa! Hold On -- This Seems Excessive!
  • 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. 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.
    • There are two ways we can organize our unit tests:
    • Inside the project
    • Outside the project
    • My personal preference is outside of the project. Here’s why:
    • Keeps our code and unit tests physically separate.
    • Avoids the double-build conundrum.
    • Allows us to close the unit test project when desirable.
    • Allows us to run tests against projects in multiple locations.
    Setting Up Your Project For TDD http://raptureinvenice.blogspot.com/2008/04/better-way-to-set-up-flexunit.html Reference:
  • 14.
    • Create a Flex or AIR project. (e.g., twitterme)
    • Create a Flex or AIR unit testing project. (e.g., twitterme-tests)
    • Add twitterme/src to the source path of twitterme-tests.
    • Add a boilerplate TestRunner application to twitterme-tests.
    • Add flexunit.swc to twitterme-tests/libs.
    Setting Up Your Project For TDD http://code.google.com/p/as3flexunitlib/ References: http://raptureinvenice.blogspot.com/2008/04/better-way-to-set-up-flexunit.html
  • 15. Working Session
  • 16. Wait! We Need a Change!
  • 17. What Have We Accomplished?
  • 18. Gain #1: We have a clean, stable piece of code
    • We know the client code will be easy to use, because we drove the code based on the client itself!
    • We have tested the code as thoroughly as we can using unit tests.
    • We have kept the unit tests as an artifact of the coding effort so that we can continually re-run the tests as needed.
    • Code usage is already documented for our customers!
  • 19. Gain #2: We will feel confident making changes to the code
    • 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!
    • We don’t have to fear the major changes that will likely be made later.
    Because what is the one constant in software development? CHANGE.
  • 20.
    • dpuint offers some enhancements over FlexUnit that you might find valuable. The key differences are:
    • Better asynchronous support
    • Sequencing tests
    • Cairngorn tests
    • Highly recommended if you want to test UI.
    A Newer Flex Testing Framework: dpuint
  • 21. Questions?