SlideShare uma empresa Scribd logo
1 de 47
Baixar para ler offline
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
         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
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
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
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
          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
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
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
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 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
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
          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
PHPUnderControl




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

Mais conteúdo relacionado

Semelhante a Unit-Tests

Reduce Third-Party Tool Dependencies in Your Test Framework
Reduce Third-Party Tool Dependencies in Your Test FrameworkReduce Third-Party Tool Dependencies in Your Test Framework
Reduce Third-Party Tool Dependencies in Your Test FrameworkTechWell
 
Ten10 Seminar: Test Automation, Tooling and the Future (slides)
Ten10 Seminar: Test Automation, Tooling and the Future (slides)Ten10 Seminar: Test Automation, Tooling and the Future (slides)
Ten10 Seminar: Test Automation, Tooling and the Future (slides)Ten10
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Return on Intelligence
 
OSMC 2015: Check Mk - Mehr als nur ein Add-on für Nagios by Mathias Kettner
OSMC 2015: Check Mk - Mehr als nur ein Add-on für Nagios by Mathias KettnerOSMC 2015: Check Mk - Mehr als nur ein Add-on für Nagios by Mathias Kettner
OSMC 2015: Check Mk - Mehr als nur ein Add-on für Nagios by Mathias KettnerNETWAYS
 
Branching and Merging Practices
Branching and Merging Practices Branching and Merging Practices
Branching and Merging Practices Rajesh Kumar
 
Unit Tests and Test Seams for abap Hamburg June 2017 presented
Unit Tests and Test Seams for abap Hamburg June 2017   presentedUnit Tests and Test Seams for abap Hamburg June 2017   presented
Unit Tests and Test Seams for abap Hamburg June 2017 presentedRainer Winkler
 
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...Xebia Nederland BV
 
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelEntity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelukdpe
 
Test Automation Demonstration with Dr Yongyan Wang by XBOSoft
Test Automation Demonstration with Dr Yongyan Wang by XBOSoftTest Automation Demonstration with Dr Yongyan Wang by XBOSoft
Test Automation Demonstration with Dr Yongyan Wang by XBOSoftXBOSoft
 
Automated Testing DITA Content and Customizations
Automated Testing DITA Content and CustomizationsAutomated Testing DITA Content and Customizations
Automated Testing DITA Content and CustomizationsSteve Anderson
 
Methods Over Madness 2003 Ver.
Methods Over Madness 2003 Ver.Methods Over Madness 2003 Ver.
Methods Over Madness 2003 Ver.Tom Weinberger
 
Innovate2011 DevOps TSRM RTC
Innovate2011 DevOps TSRM RTCInnovate2011 DevOps TSRM RTC
Innovate2011 DevOps TSRM RTCSteve Speicher
 
Анастасия Войтова: Здоровая психологическая атмосфера в жизни разработчика, ...
Анастасия Войтова:  Здоровая психологическая атмосфера в жизни разработчика, ...Анастасия Войтова:  Здоровая психологическая атмосфера в жизни разработчика, ...
Анастасия Войтова: Здоровая психологическая атмосфера в жизни разработчика, ...Fwdays
 
Whats New In LabVIEW 2010
Whats New In LabVIEW 2010Whats New In LabVIEW 2010
Whats New In LabVIEW 2010Danny Thomson
 
Practical Experiences Migrating Unified Modeling Language Models to IBM® Rati...
PracticalExperiences Migrating Unified Modeling Language Models to IBM® Rati...PracticalExperiences Migrating Unified Modeling Language Models to IBM® Rati...
Practical Experiences Migrating Unified Modeling Language Models to IBM® Rati...Einar Karlsen
 

Semelhante a Unit-Tests (20)

Reduce Third-Party Tool Dependencies in Your Test Framework
Reduce Third-Party Tool Dependencies in Your Test FrameworkReduce Third-Party Tool Dependencies in Your Test Framework
Reduce Third-Party Tool Dependencies in Your Test Framework
 
Xdebug
XdebugXdebug
Xdebug
 
Ten10 Seminar: Test Automation, Tooling and the Future (slides)
Ten10 Seminar: Test Automation, Tooling and the Future (slides)Ten10 Seminar: Test Automation, Tooling and the Future (slides)
Ten10 Seminar: Test Automation, Tooling and the Future (slides)
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!
 
OSMC 2015: Check Mk - Mehr als nur ein Add-on für Nagios by Mathias Kettner
OSMC 2015: Check Mk - Mehr als nur ein Add-on für Nagios by Mathias KettnerOSMC 2015: Check Mk - Mehr als nur ein Add-on für Nagios by Mathias Kettner
OSMC 2015: Check Mk - Mehr als nur ein Add-on für Nagios by Mathias Kettner
 
Branching and Merging Practices
Branching and Merging Practices Branching and Merging Practices
Branching and Merging Practices
 
Codeql Variant Analysis
Codeql Variant AnalysisCodeql Variant Analysis
Codeql Variant Analysis
 
Unit Tests and Test Seams for abap Hamburg June 2017 presented
Unit Tests and Test Seams for abap Hamburg June 2017   presentedUnit Tests and Test Seams for abap Hamburg June 2017   presented
Unit Tests and Test Seams for abap Hamburg June 2017 presented
 
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
 
Agile test tools
Agile test toolsAgile test tools
Agile test tools
 
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelEntity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
 
Test Automation Demonstration with Dr Yongyan Wang by XBOSoft
Test Automation Demonstration with Dr Yongyan Wang by XBOSoftTest Automation Demonstration with Dr Yongyan Wang by XBOSoft
Test Automation Demonstration with Dr Yongyan Wang by XBOSoft
 
Sdlc
SdlcSdlc
Sdlc
 
Automated Testing DITA Content and Customizations
Automated Testing DITA Content and CustomizationsAutomated Testing DITA Content and Customizations
Automated Testing DITA Content and Customizations
 
Methods Over Madness 2003 Ver.
Methods Over Madness 2003 Ver.Methods Over Madness 2003 Ver.
Methods Over Madness 2003 Ver.
 
Innovate2011 DevOps TSRM RTC
Innovate2011 DevOps TSRM RTCInnovate2011 DevOps TSRM RTC
Innovate2011 DevOps TSRM RTC
 
Анастасия Войтова: Здоровая психологическая атмосфера в жизни разработчика, ...
Анастасия Войтова:  Здоровая психологическая атмосфера в жизни разработчика, ...Анастасия Войтова:  Здоровая психологическая атмосфера в жизни разработчика, ...
Анастасия Войтова: Здоровая психологическая атмосфера в жизни разработчика, ...
 
Whats New In LabVIEW 2010
Whats New In LabVIEW 2010Whats New In LabVIEW 2010
Whats New In LabVIEW 2010
 
Practical Experiences Migrating Unified Modeling Language Models to IBM® Rati...
PracticalExperiences Migrating Unified Modeling Language Models to IBM® Rati...PracticalExperiences Migrating Unified Modeling Language Models to IBM® Rati...
Practical Experiences Migrating Unified Modeling Language Models to IBM® Rati...
 
What is Scrum
What is ScrumWhat is Scrum
What is Scrum
 

Mais de Tobias Schlitt

HTML to ODT to XML to PDF to …
HTML to ODT to XML to PDF to …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 painValidating XML - Avoiding the pain
Validating XML - Avoiding the painTobias Schlitt
 
XPath - A practical guide
XPath - A practical guideXPath - A practical guide
XPath - A practical guideTobias Schlitt
 
Professional XML with PHP
Professional XML with PHPProfessional XML with PHP
Professional XML with PHPTobias Schlitt
 
XML and XPath with PHP
XML and XPath with PHPXML and XPath with PHP
XML and XPath with PHPTobias Schlitt
 
WebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evilWebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evilTobias Schlitt
 

Mais de Tobias Schlitt (6)

HTML to ODT to XML to PDF to …
HTML to ODT to XML to PDF to …HTML to ODT to XML to PDF to …
HTML to ODT to XML to PDF to …
 
Validating XML - Avoiding the pain
Validating XML - Avoiding the painValidating XML - Avoiding the pain
Validating XML - Avoiding the pain
 
XPath - A practical guide
XPath - A practical guideXPath - A practical guide
XPath - A practical guide
 
Professional XML with PHP
Professional XML with PHPProfessional XML with PHP
Professional XML with PHP
 
XML and XPath with PHP
XML and XPath with PHPXML and XPath with PHP
XML and XPath with PHP
 
WebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evilWebDAV - The good, the bad and the evil
WebDAV - The good, the bad and the evil
 

Último

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 

Último (20)

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 

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