SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
UNIT TESTING IN PHP 
@chonla 
October 3, 2014
ARE YOU HURT? 
When you add a new feature or just change a single character 
and then … 
! 
◦ 
bugs appear 
◦ 
your friend’s code is not working anymore 
◦ 
it conflicts with other features
ARE YOU TIRED? 
When you add a new feature or just change a single 
character and then … 
! 
• 
You have to manually retest everything from start to ensure 
it is still working 
• 
You think it is working as you THINK but it is NOT
You do not deserve that! 
Unit testing can help you.
WHY? 
◦ 
If you test every single piece of code well 
▪ 
When you add a new code, the existing test cases will tell 
you early if there is a conflict. 
◦ 
If you test all possible test cases 
▪ 
When you add a new code, the existing test cases will tell 
you early if there is a conflict. 
◦ 
If you create unit test cases 
▪ 
It can be automatic rerun as much as you want 
◦ 
If you write a good unit test 
▪ 
It should be simple and easy to test
What help us to create quality unit test? 
• PHP 
• PHPUnit 
• Dependency Injection 
• Code coverage 
• Belief 
• and Conscious
With PHPUnit, you can 
! 
• Test your methods/functions 
• Mock your classes 
• Stub your classes 
• Stub your functions
OUTLINE 
• What is unit testing? 
• What is to be tested? 
• What does not need to be tested? 
• Benefits of unit testing 
• Unit testing FIRST principles 
• Unit testing measurement 
• Writing unit testing before/after? 
• Test structure 
• Testing tools 
• Possible questions 
• References
WHAT IS UNIT TESTING? 
A software testing method to test individual unit 
of source code — a method in class or a piece of 
code
WHAT IS TO BE TESTED? 
Everything
WHAT DOES NOT NEED TO BE TESTED? 
•Getter/Setter 
•They are so trivial. 
•Third party packages 
•Don’t repeat unnecessary testing. They have been 
already tested by their developers.
BENEFITS OF UNIT TESTING 
•Early problem discovery 
•It is better if we can find the error/problem before staging or production 
stage. 
•Facilitates change 
•Unit testing allows developers to refactor code anytime. It ensures the code 
still works correctly. 
•Simplifies integration 
•Unit testing increases confidence in integration. If everything is tested before 
integration, integration should be easier. 
•Self documentation 
•Let the test tell the story. 
•It visualises the design 
•By doing TDD, unit testing helps developers to design classes, to smell code 
mess and to refactor the code
UNIT TESTING FIRST PRINCIPLES 
•Fast — Each test should run fast, really fast. 
•Isolated — It should have no dependency involved. 
•Repeatable — It should be idempotent. 
•Self-verifying — Result should be just pass/fail, no 
extra investigation. 
•Timely — Every code change should result a new 
test.
UNIT TESTING MEASUREMENT 
•Line of code 
•Branch 
Code coverage DOES NOT guarantee that your application 
does not contain bugs or has good quality.
WRITE UNIT TESTING BEFORE/AFTER? 
•After 
•You test what you code — How can you validate 
& verify what you have done? 
•Before 
•You code what you test — TDD.
TEST STRUCTURE 
•Arrange — Given 
•Act — When 
•Assert — Then
TESTING TOOLS 
•PHPUnit 
•Mockery 
•Codeception 
•SimpleTest 
•PHPSpec
POSSIBLE QUESTIONS 
•What does unit test coverage tell you? 
•It tells you how many piece of code was tested. 
•Is high coverage good? 
•No, if it is not a good quality testing. 
•Should code coverage be in KPI? 
•No, doing 100% code coverage is not hard. 
Assert free testing can achieve that. We prefer a 
quality testing.
REFERENCES 
•http://www.artima.com/weblogs/viewpost.jsp? 
thread=126923 
•http://en.wikipedia.org/wiki/Unit_testing 
•http://www.somkiat.cc/high-test-coverage-vs-quality/ 
•http://agileinaflash.blogspot.com/2009/02/first.html 
!• 
http://www.slideshare.net/up1/tdd-with-php
YOUR QUESTION? 
Any?

Más contenido relacionado

La actualidad más candente

Test-driven development with Node.js
Test-driven development with Node.jsTest-driven development with Node.js
Test-driven development with Node.jsMirko Kiefer
 
Unit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqUnit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqXPDays
 
Writing Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designsWriting Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designslachlandonald
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD introVitaliy Kulikov
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOSPablo Villar
 
Test Presentation
Test PresentationTest Presentation
Test Presentationsetitesuk
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testingDuy Tan Geek
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentdcsunu
 
Tdd - Test Driven Development
Tdd - Test Driven DevelopmentTdd - Test Driven Development
Tdd - Test Driven DevelopmentDavid Paluy
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010guest5639fa9
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017Xavi Hidalgo
 
Automated Testing but like for PowerShell (April 2012)
Automated Testing but like for PowerShell (April 2012)Automated Testing but like for PowerShell (April 2012)
Automated Testing but like for PowerShell (April 2012)Rob Reynolds
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testingmarkstory
 

La actualidad más candente (19)

Test-driven development with Node.js
Test-driven development with Node.jsTest-driven development with Node.js
Test-driven development with Node.js
 
Tdd for php
Tdd for phpTdd for php
Tdd for php
 
Presentation delex
Presentation delexPresentation delex
Presentation delex
 
Unit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and MoqUnit Testing in Action - C#, NUnit, and Moq
Unit Testing in Action - C#, NUnit, and Moq
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
ATDD with Pepino
ATDD with PepinoATDD with Pepino
ATDD with Pepino
 
Writing Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designsWriting Better Tests - Applying Clean-Code TDD at 99designs
Writing Better Tests - Applying Clean-Code TDD at 99designs
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 
Test Presentation
Test PresentationTest Presentation
Test Presentation
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Becoming a better programmer - unit testing
Becoming a better programmer - unit testingBecoming a better programmer - unit testing
Becoming a better programmer - unit testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tdd - Test Driven Development
Tdd - Test Driven DevelopmentTdd - Test Driven Development
Tdd - Test Driven Development
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
TDD In Practice
TDD In PracticeTDD In Practice
TDD In Practice
 
Automated Testing but like for PowerShell (April 2012)
Automated Testing but like for PowerShell (April 2012)Automated Testing but like for PowerShell (April 2012)
Automated Testing but like for PowerShell (April 2012)
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
 

Similar a Unit testing in PHP

An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit TestingSahar Nofal
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitweili_at_slideshare
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven DevelopmentFerdous Mahmud Shaon
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentShawn Jones
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptxmianshafa
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Abhijeet Vaikar
 
Unit testing
Unit testingUnit testing
Unit testingPiXeL16
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1Blue Elephant Consulting
 
Agile testingandautomation
Agile testingandautomationAgile testingandautomation
Agile testingandautomationjeisner
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with LaravelTyler Johnston
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and AutomationMahesh Salaria
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
Test Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveTest Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveMalinda Kapuruge
 

Similar a Unit testing in PHP (20)

An Introduction to Unit Testing
An Introduction to Unit TestingAn Introduction to Unit Testing
An Introduction to Unit Testing
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
utplsql.pdf
utplsql.pdfutplsql.pdf
utplsql.pdf
 
Unit Testing Your Application
Unit Testing Your ApplicationUnit Testing Your Application
Unit Testing Your Application
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
Week 14 Unit Testing.pptx
Week 14  Unit Testing.pptxWeek 14  Unit Testing.pptx
Week 14 Unit Testing.pptx
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Unit Testing talk
Unit Testing talkUnit Testing talk
Unit Testing talk
 
Tdd
TddTdd
Tdd
 
Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)Unit testing (Exploring the other side as a tester)
Unit testing (Exploring the other side as a tester)
 
Unit testing
Unit testingUnit testing
Unit testing
 
An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
 
Agile testingandautomation
Agile testingandautomationAgile testingandautomation
Agile testingandautomation
 
Test Driven Development with Laravel
Test Driven Development with LaravelTest Driven Development with Laravel
Test Driven Development with Laravel
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveTest Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s Perspective
 
Agile testing
Agile testingAgile testing
Agile testing
 

Último

WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 

Último (20)

WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

Unit testing in PHP

  • 1. UNIT TESTING IN PHP @chonla October 3, 2014
  • 2. ARE YOU HURT? When you add a new feature or just change a single character and then … ! ◦ bugs appear ◦ your friend’s code is not working anymore ◦ it conflicts with other features
  • 3. ARE YOU TIRED? When you add a new feature or just change a single character and then … ! • You have to manually retest everything from start to ensure it is still working • You think it is working as you THINK but it is NOT
  • 4. You do not deserve that! Unit testing can help you.
  • 5. WHY? ◦ If you test every single piece of code well ▪ When you add a new code, the existing test cases will tell you early if there is a conflict. ◦ If you test all possible test cases ▪ When you add a new code, the existing test cases will tell you early if there is a conflict. ◦ If you create unit test cases ▪ It can be automatic rerun as much as you want ◦ If you write a good unit test ▪ It should be simple and easy to test
  • 6. What help us to create quality unit test? • PHP • PHPUnit • Dependency Injection • Code coverage • Belief • and Conscious
  • 7. With PHPUnit, you can ! • Test your methods/functions • Mock your classes • Stub your classes • Stub your functions
  • 8. OUTLINE • What is unit testing? • What is to be tested? • What does not need to be tested? • Benefits of unit testing • Unit testing FIRST principles • Unit testing measurement • Writing unit testing before/after? • Test structure • Testing tools • Possible questions • References
  • 9. WHAT IS UNIT TESTING? A software testing method to test individual unit of source code — a method in class or a piece of code
  • 10. WHAT IS TO BE TESTED? Everything
  • 11. WHAT DOES NOT NEED TO BE TESTED? •Getter/Setter •They are so trivial. •Third party packages •Don’t repeat unnecessary testing. They have been already tested by their developers.
  • 12. BENEFITS OF UNIT TESTING •Early problem discovery •It is better if we can find the error/problem before staging or production stage. •Facilitates change •Unit testing allows developers to refactor code anytime. It ensures the code still works correctly. •Simplifies integration •Unit testing increases confidence in integration. If everything is tested before integration, integration should be easier. •Self documentation •Let the test tell the story. •It visualises the design •By doing TDD, unit testing helps developers to design classes, to smell code mess and to refactor the code
  • 13. UNIT TESTING FIRST PRINCIPLES •Fast — Each test should run fast, really fast. •Isolated — It should have no dependency involved. •Repeatable — It should be idempotent. •Self-verifying — Result should be just pass/fail, no extra investigation. •Timely — Every code change should result a new test.
  • 14. UNIT TESTING MEASUREMENT •Line of code •Branch Code coverage DOES NOT guarantee that your application does not contain bugs or has good quality.
  • 15. WRITE UNIT TESTING BEFORE/AFTER? •After •You test what you code — How can you validate & verify what you have done? •Before •You code what you test — TDD.
  • 16. TEST STRUCTURE •Arrange — Given •Act — When •Assert — Then
  • 17. TESTING TOOLS •PHPUnit •Mockery •Codeception •SimpleTest •PHPSpec
  • 18. POSSIBLE QUESTIONS •What does unit test coverage tell you? •It tells you how many piece of code was tested. •Is high coverage good? •No, if it is not a good quality testing. •Should code coverage be in KPI? •No, doing 100% code coverage is not hard. Assert free testing can achieve that. We prefer a quality testing.
  • 19. REFERENCES •http://www.artima.com/weblogs/viewpost.jsp? thread=126923 •http://en.wikipedia.org/wiki/Unit_testing •http://www.somkiat.cc/high-test-coverage-vs-quality/ •http://agileinaflash.blogspot.com/2009/02/first.html !• http://www.slideshare.net/up1/tdd-with-php