Unit-Tests

1,252 views

Published on

Slides from my unit-testing talk at the PHP World Kongress

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,252
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
50
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Unit-Tests

  1. 1. Unit-Tests Schnell und einfach selbst gemacht TobiasSchlitt <toby@php.net> PHP World Kongress 2009 2009-11-24 Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 1 / 25
  2. 2. About me Tobias Schlitt <toby@php.net> PHP since 2001 Freelancing consultant Qualified IT Specialist Studying CS at TU Dortmund (finishing mid 2010) OSS addicted eZ Components PHPUnit Various other projects . . . Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 2 / 25
  3. 3. Overview 1 Testing 2 PHPUnit 3 Advanced scenarios (optional) 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 3 / 25
  4. 4. Outline 1 Testing Methods of testing Unit tests 2 PHPUnit 3 Advanced scenarios (optional) 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 4 / 25
  5. 5. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  6. 6. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  7. 7. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  8. 8. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  9. 9. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  10. 10. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  11. 11. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  12. 12. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  13. 13. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  14. 14. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  15. 15. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  16. 16. Ways of testing Automatic vs. manual Developer vs. tester Internal vs. external Back end vs. front end Code vs. appearance Functional vs. non-functional Dynamic vs. static Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 6 / 25
  17. 17. Test methods Unit tests Integration tests Regression tests Acceptance tests Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 7 / 25
  18. 18. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  19. 19. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  20. 20. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  21. 21. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  22. 22. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  23. 23. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  24. 24. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  25. 25. Unit tests Validate functionality Test a single unit of code Avoid regressions Verify interfaces Test bugs dedicatedly Force code modularization Migrate safely Test driven development (TDD) Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 8 / 25
  26. 26. Outline 1 Testing 2 PHPUnit Installation PHPUnit basics Code examples 3 Advanced scenarios (optional) 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 9 / 25
  27. 27. PHPUnit Port of JUnit to PHP Many enhancements Database tests Code coverage Data providers Invented by Sebastian Bergmann Standard for unit testing in PHP http://www.phpunit.de/ Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 10 / 25
  28. 28. Installation Via PEAR $ pear channel-discover pear.phpunit.de $ pear install phpunit/PHPUnit Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 11 / 25
  29. 29. PHPUnit basics YourClass Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  30. 30. PHPUnit basics YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  31. 31. PHPUnit basics YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  32. 32. PHPUnit basics TestCase YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  33. 33. PHPUnit basics TestRunner TestCase YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  34. 34. PHPUnit basics TestRunner TestCase YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  35. 35. Let’s dig into some code Let’s dig into some code Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 13 / 25
  36. 36. Outline 1 Testing 2 PHPUnit 3 Advanced scenarios (optional) Custom test environment Testing a WebDAV server Testing graphic generation Testing parsers 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 14 / 25
  37. 37. eZ Component test runner Custom test runner Integrated auto loading Component base testing Run all tests Extended test case / suite classes Custom assertions Database testing Utility functions Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 15 / 25
  38. 38. eZ Webdav component Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 16 / 25
  39. 39. Semi-automatic regression tests Manual client test run Defined test receipe Capture request / response data Replay request in unit tests Detect response regressions Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 17 / 25
  40. 40. Binary regressions Binary differences in generated images Test failures depending on PHP version GD version Operating system Images visually equivalent Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 18 / 25
  41. 41. Custom assertions Custom assertion Custom equality constraint Based on ImageMagick Allows defined gap Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 19 / 25
  42. 42. Untestable code Parsers are highly dependant De-coupling hardly possible Huge amount of mock objects Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 20 / 25
  43. 43. Integration tests Test parser as a whole Small test files Manually create / validate Large overall tests Manual inspection of generated data Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 21 / 25
  44. 44. Outline 1 Testing 2 PHPUnit 3 Advanced scenarios (optional) 4 The end Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 22 / 25
  45. 45. Questions / Answers Questions? Feedback? Critics? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 23 / 25
  46. 46. The end I hope you enjoyed the session Slides and material http://schlitt.info/opensource http://www.slideshare.net/tobyS Contact: Tobias Schlitt <toby@php.net> Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 24 / 25
  47. 47. PHPUnderControl Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 25 / 25

×