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.
9. Why Should I Unit Test?
• Quality
• No amount of testing has ever put quality into a
product
10. Why Should I Unit Test?
• Quality
• No amount of testing has ever put quality into a
product
• Explore unknown code
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. 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. 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
21. PHPUnit
• PHP version of xUnit testing system
• Standard testing harness for Joomla
• Code: http://www.phpunit.de/
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
45. Before I write code?? Why?
• Small steps toward a solution
46. Before I write code?? Why?
• Small steps toward a solution
• Focus your mind
47. Before I write code?? Why?
• Small steps toward a solution
• Focus your mind
• Encourage simpler code
48. Before I write code?? Why?
• Small steps toward a solution
• Focus your mind
• Encourage simpler code
• No more code than necessary
49. Before I write code?? Why?
• Small steps toward a solution
• Focus your mind
• Encourage simpler code
• No more code than necessary
• Actually works
52. Can I Improve JObservable?
• Notifies the observers
• Maintains 2 different lists
53. Can I Improve JObservable?
• Notifies the observers
• Maintains 2 different lists
• Single Responsibility Principle
54. Can I Improve JObservable?
• Notifies the observers
• Maintains 2 different lists
• Single Responsibility Principle
• "Every class should have one and
only one responsibility"
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