PHPUnit Automated Unit Testing Framework

Download PHPUnit Automated Unit Testing Framework

Post on 17-May-2015

6.610 views

Category:

Technology

0 download

Embed Size (px)

DESCRIPTION

An introduction to PHPUnit, written for the PHP Meetup group I run.

TRANSCRIPT

<ul><li> 1. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHPUnit Automated Unit Testing Framework June 5, 2008</li></ul> <p> 2. Dave Ross I grew up around computers, fell in love with the Internet way back in 1994, and built a successful career around my interests in computers and business. My career focus has been on e-commerce, and in my personal time I study issues related to digital identity, trust, and reputation tracking. Im also an small business owner, an avid Scrabble player, and a b-movie junkie. 9 years professional development experience PHP developer, certified Java developer LinkedIn profile: http://www.linkedin.com/pub/2/832/9b0 Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org 3. The West Suburban Chicago PHP Meetup </p> <ul><li>Meets first Thursday of every month </li></ul> <ul><li>Usually at the Panera in Wheaton </li></ul> <ul><li>Official Meetup page: </li></ul> <ul><li>http://php.meetup.com/381 </li></ul> <ul><li>Blog: </li></ul> <ul><li>http://suburbanchicagophp.org </li></ul> <p>Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org 4. </p> <ul><li>PHPUnitis a member of the xUnit family of testing frameworks (SUnit, jUnit, pyUnit...)</li></ul> <ul><li>Written for PHP 5.x, older versions supported PHP 4.x </li></ul> <p>Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org 5. </p> <ul><li><ul><li>Unit testing: </li></ul></li></ul> <ul><li><ul><li>Testing thesmallesttestable parts </li></ul></li></ul> <ul><li><ul><li>of an application </li></ul></li></ul> <ul><li><ul><li>(Functions, Classes, Macros) </li></ul></li></ul> <p>Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org 6. </p> <ul><li><ul><li>The xUnit frameworks provide a </li></ul></li></ul> <ul><li><ul><li>way toautomateunit tests </li></ul></li></ul> <ul><li><ul><li>If you automate your tests, </li></ul></li></ul> <ul><li><ul><li>the quality of your tests </li></ul></li></ul> <ul><li><ul><li>is consistent </li></ul></li></ul> <p>Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org 7. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Make iteasyto test, and you'll do it more often. If you use version control, test before every check-in 8. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org You can wrap a set of tests into atest suite A suite tests larger units of your application, even the application itself 9. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHP itself is tested using automated tests They use a framework calledphpt 10. The PHPUnit Pocket Guide Tells you everything you need to know when writing PHPUnit test cases Buy the book, or read the HTML version at: http://www.phpunit.de/pocket_guide/index.en.php Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org 11. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Let's look at a test case! 12. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org 13. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Tests should be run against a known, fixed state called afixture setUp() creates this state tearDown() destroys the state and puts things back the way they were 14. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test cases are implemented as functions whose names start with the word test This example has: testNewArrayIsEmpty() testArrayContainsAnElement() 15. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Runa PHPUnit test case with thephpunitcommand phpunit UnitTest UnitTest.php tells PHPUnit to look for a class UnitTest in the UnitTest.php file (filename is optional) 16. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org phpunit ArrayTest PHPUnit 3.3.0 by Sebastian Bergmann. .. Time: 0 seconds OK (2 tests) 17. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Can output test logs to a variety offormats : GraphViz JSON TAP XML 18. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test suite + Exported results allows for Continuous Integration 19. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Continuous integration is a way to automatically run your test suite regularly Once a day... Once an hour... Every time someone checks in code... 20. Official PHPUnit page: http://www.phpunit.de/ PHPUnit Pocket Guide: http://www.phpunit.de/pocket_guide Effective Unit Testing: http://www.acm.org/ubiquity/views/t_burns_1.html For More Information Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org 21. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org</p>