際際滷

際際滷Share a Scribd company logo
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
About me



         Tobias Schlitt <toby@php.net>
         PHP since 2001
         Freelancing consultant
         Quali鍖ed IT Specialist
         Studying CS at TU Dortmund
         (鍖nishing mid 2010)
         OSS addicted
                eZ Components
                PHPUnit
                Various other projects . . .




Tobias Schlitt (PHP World Kongress 2009)       Unit-Tests   2009-11-24   2 / 25
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
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
A little survey . . .




   Do you test?
       When?
          How?
          Who?




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   5 / 25
A little survey . . .




   Do you test?
       When?
          How?
          Who?




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   5 / 25
A little survey . . .




   Do you test?
       When?
          How?
          Who?




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   5 / 25
A little survey . . .




   Do you test?
       When?
          How?
          Who?




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   5 / 25
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
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
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
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
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
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
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
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
Test methods




          Unit tests
          Integration tests
          Regression tests
          Acceptance tests




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   7 / 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
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
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
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
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
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
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
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
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
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
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
PHPUnit basics




                                           YourClass




Tobias Schlitt (PHP World Kongress 2009)    Unit-Tests   2009-11-24   12 / 25
PHPUnit basics




                       YourClass                        YourClassTest




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests               2009-11-24   12 / 25
PHPUnit basics




                       YourClass                        YourClassTest




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests               2009-11-24   12 / 25
PHPUnit basics




                                                          TestCase




                       YourClass                        YourClassTest




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests                2009-11-24   12 / 25
PHPUnit basics



                                           TestRunner




                                                             TestCase




                       YourClass                           YourClassTest




Tobias Schlitt (PHP World Kongress 2009)      Unit-Tests                2009-11-24   12 / 25
PHPUnit basics



                                           TestRunner




                                                             TestCase




                       YourClass                           YourClassTest




Tobias Schlitt (PHP World Kongress 2009)      Unit-Tests                2009-11-24   12 / 25
Lets dig into some code




 Lets dig into some code




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   13 / 25
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
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
eZ Webdav component




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   16 / 25
Semi-automatic regression tests




          Manual client test run
          De鍖ned 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
Binary regressions




          Binary di鍖erences 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
Custom assertions




          Custom assertion
          Custom equality constraint
                 Based on ImageMagick
                 Allows de鍖ned gap




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   19 / 25
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
Integration tests




          Test parser as a whole
          Small test 鍖les
                 Manually create / validate
          Large overall tests
                 Manual inspection of generated data




Tobias Schlitt (PHP World Kongress 2009)      Unit-Tests   2009-11-24   21 / 25
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
Questions / Answers




                                  Questions? Feedback? Critics?




Tobias Schlitt (PHP World Kongress 2009)     Unit-Tests           2009-11-24   23 / 25
The end




          I hope you enjoyed the session
          際際滷s 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
PHPUnderControl




Tobias Schlitt (PHP World Kongress 2009)   Unit-Tests   2009-11-24   25 / 25
Ad

Recommended

The Test way
The Test way
Mikhail Grinfeld
Unit testing for Cocoa developers
Unit testing for Cocoa developers
Graham Lee
Pragmatic Introduction to PHP Unit Testing (2015)
Pragmatic Introduction to PHP Unit Testing (2015)
Peter Kofler
The Evolution of Development Testing
The Evolution of Development Testing
Cathal King
Automatic Comment Analysis
Automatic Comment Analysis
Jerome DERN
Dev305 Entity Framework 4 Emergency 際際滷s
Dev305 Entity Framework 4 Emergency 際際滷s
Eric Nelson
Xdebug
Xdebug
Tobias Schlitt
Profiling PHP Applications
Profiling PHP Applications
Michal Hat叩k
Test
Test
Eddie Kao
Test Automation
Test Automation
Rodrigo Paiva
Intro to PHP Testing
Intro to PHP Testing
Ran Mizrahi
PHPUnit & Continuous Integration: An Introduction
PHPUnit & Continuous Integration: An Introduction
alexmace
Cursus phpunit
Cursus phpunit
Nick Belhomme
Your code are my tests
Your code are my tests
Michelangelo van Dam
Test in action week 2
Test in action week 2
Yi-Huan Chan
Test Driven Development with PHPUnit
Test Driven Development with PHPUnit
Mindfire Solutions
Test Driven Development with PHPUnit
Test Driven Development with PHPUnit
Tuan Nguyen
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
LB Denker
Test in action week 1
Test in action week 1
Yi-Huan Chan
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
Unit testing in PHP
Unit testing in PHP
Chonlasith Jucksriporn
Regression Testing with Symfony
Regression Testing with Symfony
Joachim Unger
PHPUnit from a developer's perspective
PHPUnit from a developer's perspective
Tushar Joshi
Unit Testing Your Application
Unit Testing Your Application
Paladin Web Services
Automated testing 101
Automated testing 101
Tabitha Chapman
Test Driven Development
Test Driven Development
ZendCon
Unit and integration Testing
Unit and integration Testing
David Berliner
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to Integrate
LB Denker
HTML to ODT to XML to PDF to
HTML to ODT to XML to PDF to
Tobias Schlitt
Validating XML - Avoiding the pain
Validating XML - Avoiding the pain
Tobias Schlitt

More Related Content

Similar to Unit-Tests (20)

Test
Test
Eddie Kao
Test Automation
Test Automation
Rodrigo Paiva
Intro to PHP Testing
Intro to PHP Testing
Ran Mizrahi
PHPUnit & Continuous Integration: An Introduction
PHPUnit & Continuous Integration: An Introduction
alexmace
Cursus phpunit
Cursus phpunit
Nick Belhomme
Your code are my tests
Your code are my tests
Michelangelo van Dam
Test in action week 2
Test in action week 2
Yi-Huan Chan
Test Driven Development with PHPUnit
Test Driven Development with PHPUnit
Mindfire Solutions
Test Driven Development with PHPUnit
Test Driven Development with PHPUnit
Tuan Nguyen
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
LB Denker
Test in action week 1
Test in action week 1
Yi-Huan Chan
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
Unit testing in PHP
Unit testing in PHP
Chonlasith Jucksriporn
Regression Testing with Symfony
Regression Testing with Symfony
Joachim Unger
PHPUnit from a developer's perspective
PHPUnit from a developer's perspective
Tushar Joshi
Unit Testing Your Application
Unit Testing Your Application
Paladin Web Services
Automated testing 101
Automated testing 101
Tabitha Chapman
Test Driven Development
Test Driven Development
ZendCon
Unit and integration Testing
Unit and integration Testing
David Berliner
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to Integrate
LB Denker
Intro to PHP Testing
Intro to PHP Testing
Ran Mizrahi
PHPUnit & Continuous Integration: An Introduction
PHPUnit & Continuous Integration: An Introduction
alexmace
Test in action week 2
Test in action week 2
Yi-Huan Chan
Test Driven Development with PHPUnit
Test Driven Development with PHPUnit
Mindfire Solutions
Test Driven Development with PHPUnit
Test Driven Development with PHPUnit
Tuan Nguyen
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
LB Denker
Test in action week 1
Test in action week 1
Yi-Huan Chan
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
Regression Testing with Symfony
Regression Testing with Symfony
Joachim Unger
PHPUnit from a developer's perspective
PHPUnit from a developer's perspective
Tushar Joshi
Automated testing 101
Automated testing 101
Tabitha Chapman
Test Driven Development
Test Driven Development
ZendCon
Unit and integration Testing
Unit and integration Testing
David Berliner
Developer testing 201: When to Mock and When to Integrate
Developer testing 201: When to Mock and When to Integrate
LB Denker

More from Tobias Schlitt (7)

HTML to ODT to XML to PDF to
HTML to ODT to XML to PDF to
Tobias Schlitt
Validating XML - Avoiding the pain
Validating XML - Avoiding the pain
Tobias Schlitt
XPath - A practical guide
XPath - A practical guide
Tobias Schlitt
Professional XML with PHP
Professional XML with PHP
Tobias Schlitt
Xdebug
Xdebug
Tobias Schlitt
XML and XPath with PHP
XML and XPath with PHP
Tobias Schlitt
WebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evil
Tobias Schlitt
HTML to ODT to XML to PDF to
HTML to ODT to XML to PDF to
Tobias Schlitt
Validating XML - Avoiding the pain
Validating XML - Avoiding the pain
Tobias Schlitt
XPath - A practical guide
XPath - A practical guide
Tobias Schlitt
Professional XML with PHP
Professional XML with PHP
Tobias Schlitt
XML and XPath with PHP
XML and XPath with PHP
Tobias Schlitt
WebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evil
Tobias Schlitt
Ad

Recently uploaded (20)

Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Edge AI and Vision Alliance
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Key Requirements to Successfully Implement Generative AI in Edge DevicesOpt...
Edge AI and Vision Alliance
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
Ad

Unit-Tests

  • 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. About me Tobias Schlitt <toby@php.net> PHP since 2001 Freelancing consultant Quali鍖ed IT Specialist Studying CS at TU Dortmund (鍖nishing mid 2010) OSS addicted eZ Components PHPUnit Various other projects . . . Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 2 / 25
  • 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. 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. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  • 6. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  • 7. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  • 8. A little survey . . . Do you test? When? How? Who? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 5 / 25
  • 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. 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. 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. 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. 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. 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. 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. 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. Test methods Unit tests Integration tests Regression tests Acceptance tests Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 7 / 25
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. PHPUnit basics YourClass Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 30. PHPUnit basics YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 31. PHPUnit basics YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 32. PHPUnit basics TestCase YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 33. PHPUnit basics TestRunner TestCase YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 34. PHPUnit basics TestRunner TestCase YourClass YourClassTest Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 12 / 25
  • 35. Lets dig into some code Lets dig into some code Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 13 / 25
  • 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. 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. eZ Webdav component Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 16 / 25
  • 39. Semi-automatic regression tests Manual client test run De鍖ned 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. Binary regressions Binary di鍖erences 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. Custom assertions Custom assertion Custom equality constraint Based on ImageMagick Allows de鍖ned gap Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 19 / 25
  • 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. Integration tests Test parser as a whole Small test 鍖les 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. 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. Questions / Answers Questions? Feedback? Critics? Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 23 / 25
  • 46. The end I hope you enjoyed the session 際際滷s 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. PHPUnderControl Tobias Schlitt (PHP World Kongress 2009) Unit-Tests 2009-11-24 25 / 25