Unit Testing Your Application

1,454 views
1,264 views

Published on

From a Joomla Day Midwest presentation, this focuses on unit testing in the open source Joomla project. The slides wrap around two demonstrations that cannot be included here.

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

  • Be the first to like this

No Downloads
Views
Total views
1,454
On SlideShare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
Downloads
132
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Breaking your application up into chunks (units) and ensuring each unit does what it is supposed to do.\n
  • Typically a single class, because classes are the smallest independent pieces of your application.\n
  • Typically with a "test harness," a body of code that will call the unit under test and check the results it gets back against a predicted value.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Unit Testing Your Application

    1. 1. What is Unit Testing?
    2. 2. What is Unit Testing?Breaking an application up into chunks (units) and testing each unit individually.
    3. 3. Whats a “unit”?
    4. 4. Whats a “unit”? Typically a single class, because classes are thesmallest independent pieces of your application.
    5. 5. How do I test it?
    6. 6. How do I test it? With a “test harness.” (code that calls the unit being tested andcompares the results to a predicted value)
    7. 7. Why Should I Unit Test?
    8. 8. Why Should I Unit Test?• Quality
    9. 9. Why Should I Unit Test?• Quality • No amount of testing has ever put quality into a product
    10. 10. Why Should I Unit Test?• Quality • No amount of testing has ever put quality into a product• Explore unknown code
    11. 11. Why Should I Unit Test?• Quality • No amount of testing has ever put quality into a product• Explore unknown code • "What happens if I poke it here?"
    12. 12. Why Should I Unit Test?• Quality • No amount of testing has ever put quality into a product• Explore unknown code • "What happens if I poke it here?"• Reveal misunderstandings
    13. 13. Why Should I Unit Test?• Quality • No amount of testing has ever put quality into a product• Explore unknown code • "What happens if I poke it here?"• Reveal misunderstandings• Confidence
    14. 14. When Should I Write Unit Tests?
    15. 15. When Should I Write Unit Tests?• Before writing new code
    16. 16. When Should I Write Unit Tests?• Before writing new code• To illustrate a bug in existing code
    17. 17. When Should I Write Unit Tests?• Before writing new code• To illustrate a bug in existing code• Before trying to refactor untested code
    18. 18. PHPUnit
    19. 19. PHPUnit• PHP version of xUnit testing system
    20. 20. PHPUnit• PHP version of xUnit testing system• Standard testing harness for Joomla
    21. 21. PHPUnit• PHP version of xUnit testing system• Standard testing harness for Joomla• Code: http://www.phpunit.de/
    22. 22. PHPUnit• PHP version of xUnit testing system• Standard testing harness for Joomla• Code: http://www.phpunit.de/• Manual: http://www.phpunit.de/manual/ current/en/index.html
    23. 23. PHPunit Tests
    24. 24. PHPunit Tests• Test suite files: "...Test.php"
    25. 25. PHPunit Tests• Test suite files: "...Test.php"• Testing methods: "test...()"
    26. 26. PHPUnit Testing Procedure
    27. 27. PHPUnit Testing Procedure • Instantiate class
    28. 28. PHPUnit Testing Procedure • Instantiate class • Execute method
    29. 29. PHPUnit Testing Procedure • Instantiate class • Execute method • Assert results
    30. 30. Testing Assertions
    31. 31. Testing Assertions• Locate Failures Easily
    32. 32. Testing Assertions• Locate Failures Easily • Separate tests
    33. 33. Testing Assertions• Locate Failures Easily • Separate tests • Detailed message
    34. 34. Legacy code
    35. 35. Legacy code• Code that has no unit tests
    36. 36. Legacy code• Code that has no unit tests • Cannot be trusted
    37. 37. Exploring Legacy code
    38. 38. Exploring Legacy code• Discover actual functionality
    39. 39. Exploring Legacy code• Discover actual functionality• Discover new bugs
    40. 40. Exploring Legacy code• Discover actual functionality• Discover new bugs• Prepare for any code changes
    41. 41. JObservable/JObserver
    42. 42. Developing new code
    43. 43. Developing new code Write Tests First!!
    44. 44. Before I write code?? Why?
    45. 45. Before I write code?? Why?• Small steps toward a solution
    46. 46. Before I write code?? Why?• Small steps toward a solution • Focus your mind
    47. 47. Before I write code?? Why?• Small steps toward a solution • Focus your mind • Encourage simpler code
    48. 48. Before I write code?? Why?• Small steps toward a solution • Focus your mind • Encourage simpler code • No more code than necessary
    49. 49. Before I write code?? Why?• Small steps toward a solution • Focus your mind • Encourage simpler code • No more code than necessary • Actually works
    50. 50. Can I Improve JObservable?
    51. 51. Can I Improve JObservable?• Notifies the observers
    52. 52. Can I Improve JObservable?• Notifies the observers• Maintains 2 different lists
    53. 53. Can I Improve JObservable?• Notifies the observers• Maintains 2 different lists• Single Responsibility Principle
    54. 54. Can I Improve JObservable?• Notifies the observers• Maintains 2 different lists• Single Responsibility Principle • "Every class should have one and only one responsibility"
    55. 55. JObserverList
    56. 56. Arlen Walkeremail: Arlen.Walker@gmail.comTwitter: @Arlengithub: http://github.com/Paladinslideshare: http://www.slideshare.net/paladinwebservicesspeakerdeck: http://speakerdeck.com/u/paladinspkr8: http://speakerrate.com/speakers/7896-arlen

    ×