Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unit Testing Your Application

Unit Testing Your Application

A presentation from Joomla Day Midwest 2011 in Milwaukee, these slides were wrapped around two demonstrations of unit testing in the open source joomla framework.

Arlen Walker

November 12, 2011
Tweet

Other Decks in Programming

Transcript

  1. What is Unit Testing? Breaking an application up into chunks

    (units) and testing each unit individually. Friday, November 11, 11
  2. What's a “unit”? Typically a single class, because classes are

    the smallest independent pieces of your application. Friday, November 11, 11
  3. How do I test it? With a “test harness.” (code

    that calls the unit being tested and compares the results to a predicted value) Friday, November 11, 11
  4. • 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 Why Should I Unit Test? Friday, November 11, 11
  5. • Before writing new code • To illustrate a bug

    in existing code • Before trying to refactor untested code When Should I Write Unit Tests? Friday, November 11, 11
  6. • 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 PHPUnit Friday, November 11, 11
  7. • Test suite files: "...Test.php" • Testing methods: "test...()" PHPunit

    Tests Friday, November 11, 11
  8. • Instantiate class • Execute method • Assert results PHPUnit

    Testing Procedure Friday, November 11, 11
  9. Testing Assertions • Locate Failures Easily • Separate tests •

    Detailed message Friday, November 11, 11
  10. • Code that has no unit tests • Cannot be

    trusted Legacy code Friday, November 11, 11
  11. • Discover actual functionality • Discover new bugs • Prepare

    for any code changes Exploring Legacy code Friday, November 11, 11
  12. JObservable/JObserver Friday, November 11, 11

  13. Write Tests First!! Developing new code Friday, November 11, 11

  14. • Small steps toward a solution • Focus your mind

    • Encourage simpler code • No more code than necessary • Actually works Before I write code?? Why? Friday, November 11, 11
  15. • Notifies the observers • Maintains 2 different lists •

    Single Responsibility Principle • "Every class should have one and only one responsibility" Can I Improve JObservable? Friday, November 11, 11
  16. JObserverList Friday, November 11, 11

  17. Arlen Walker email: [email protected] Twitter: @Arlen github: http://github.com/Paladin slideshare: http://www.slideshare.net/paladinwebservices

    speakerdeck: http://speakerdeck.com/u/paladin spkr8: http://speakerrate.com/speakers/7896-arlen Friday, November 11, 11