Presentation is loading. Please wait.

Presentation is loading. Please wait.

Catch Your Bugs By Surprise: Testing with PHPUnit Orion Ifland Tipping Canoe 2011-09-26.

Similar presentations


Presentation on theme: "Catch Your Bugs By Surprise: Testing with PHPUnit Orion Ifland Tipping Canoe 2011-09-26."— Presentation transcript:

1 Catch Your Bugs By Surprise: Testing with PHPUnit Orion Ifland Tipping Canoe 2011-09-26

2 About Me Been using PHP off and on since 2000 Started writing unit tests a while back, but didn't understand the value until seeing a TDD talk Hate doing repetetive tasks on computers Willing to admit that I rarely get code right the first time Supposedly idolize Sebastian Bergman

3 About You Who uses OO programming (at least some classes) in PHP? Who uses frameworks? Which ones? Who has done unit or integration testing?

4 Defenitions Unit testing Covers small block of code, low-level Run fast Pretty stable Integration testing Covers whole/larger system Run more slowly Very sensetive to change

5 Installing PHPUnit Install via... PEAR Unzip Just a bunch of PHP files Framework for writing tests CLI program for running tests

6 Writing a test Testable code Framework base class

7 Using PHPUnit CLI program (phpunit or phpunit.bat) Running from Eclipse Zend Debugger External Tools PHPsrc plugin

8 Running Several Tests Filters phpunit --filter Unicorn Directories Name your files *Test.php @datasource

9 Selenium Selenium IDE (Firefox Plugin) Add PHP support Write and run simple tests Export PHP code Selenium Server (any browser) A standalone java.jar file Download and run: java -jar selenium-server.jar

10 Test-Driven Development Evolutionary/agile development that prevents regressions by writing tests first and constantly running them Method Red – write a new, failing test for a new feature Green – write just the code needed to pass the test and implement the feature Refactor – clean up code, make sure everything still works

11 TDD Example Ping Pong

12 TDD Advantages No regressions: no fear of changing or adding things, preventing 'technical debt' Tests document functionality, providing sample code and showing what is expected For moderately complex code, it speeds up my dev time Shows/proves what's really working and facilitates continuous deployment

13 TDD Realities It requires discipline to stick to red-green-refactor It's hard to retrofit existing testless code It's more code to write and maintain

14 Questions? Slides + code will be up on www.winnipegphp.comwww.winnipegphp.com Links relevant to the talk: PHPUnit: http://phpunit.de/http://phpunit.de/ Selenium IDE/Server: http://seleniumhq.org/download/http://seleniumhq.org/download/ Eclipse Plugin:http://www.phpsrc.org/http://www.phpsrc.org/ PHP 'Format' for Selenium IDEhttp://code.google.com/p/selenium/source/browse/tru nk/ide/plugins/php-format/src/content/formats/php- base.jshttp://code.google.com/p/selenium/source/browse/tru nk/ide/plugins/php-format/src/content/formats/php- base.js


Download ppt "Catch Your Bugs By Surprise: Testing with PHPUnit Orion Ifland Tipping Canoe 2011-09-26."

Similar presentations


Ads by Google