SlideShare a Scribd company logo
Unit Test
example by PHPUnit
Eric G

2019
What is a unit test ?
A unit test is a piece of code that invokes a unit of
work and checks one specific end result of that unit of
work. If the assumptions on the end result turn out to
be wrong, the unit test has failed. A unit test’s scope
can span as little as a method or as much as multiple
classes.
How you test right
now ?
AuthService

.login {

…

}
What are problems in
previous case?
• It’s considered an integration test

• It’s redundant for many test cases

• Must test every cases after modifying the code in the
same unit

• Other team members don’t know how to test it
What makes a good unit test
• It should be automated and repeatable

• It should be easy to implement

• It should be relevant tomorrow

• Anyone should be able to run it at the push of a button

• It should be run quickly

• It should be consistent in its results (it always returns the same result if you don’t change anything
between runs)

• It should have full control of the unit under test

• It should be fully isolated (runs independently of other tests)

• When it fails, it should be easy to detect what was expected and determine how to pinpoint the
problem

Art of unit testing 2nd(1.2 Properties of a good unit test). Roy Osherove
Writing the first unit
test
Demo
Writing the first test
Unit test framework
PHPUnit
Why we want to use unites framework
• It can be automated and repeatable

• It can be easy to implement

• It can be relevant tomorrow

• Anyone can be able to run it at the push of a button

• It can be run quickly

• It should be consistent in its results (it always returns the same result if you don’t change anything
between runs)

• It can have full control of the unit under test

• It can be fully isolated (runs independently of other tests)

• When it fails, it should be easy to detect what was expected and determine how to pinpoint the
problem
Setting PHPUnit in PHPStorm
PChomePay unit test basic
PChomePay unit test basic
PChomePay unit test basic
PChomePay unit test basic
Demo
Types of assertions
• Return value

• State changing

• Object Interaction
Important rules in unit test
• AAA(Got When Then) pattern

• Test naming

• Single Assertion
Setup & Teardown
Art of unit testing 2nd(Figure 2.5 How NUnit calls SetUp and TearDown). Roy Osherove
Demo

More Related Content

What's hot (20)

PPT
N Unit Presentation
priya_trivedi
 
PDF
How and what to unit test
Eugenio Lentini
 
PPTX
Introduction to unit testing in python
Anirudh
 
PPTX
NUnit Features Presentation
Shir Brass
 
PDF
Unit testing.pptx [repaired]
Mohammad Asmar
 
PPT
Intro to junit
Rakesh Srivastava
 
PPTX
White box testing
Mani Kanth
 
PPTX
Unit 4 testing
TharuniDiddekunta
 
ODP
Testing Philosphies
Rob Kaufman
 
PPT
New Features Of Test Unit 2.x
djberg96
 
PPTX
Unit Testing with Python
MicroPyramid .
 
PPTX
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Jacinto Limjap
 
PPTX
ScioTalks | Coverage Based Testing
Scio Consulting
 
ODP
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
dcieslak
 
PPT
Black box testing
Abdul Basit
 
PPTX
Equivalence class testing
Mani Kanth
 
PPTX
Software Testing Foundations Part 4 - Black Box Testing
Nikita Knysh
 
PPTX
H testing and debugging
missstevenson01
 
PPTX
Unit Testing
Hatem Al Sum
 
PPTX
5 black box and grey box testing
Yisal Khan
 
N Unit Presentation
priya_trivedi
 
How and what to unit test
Eugenio Lentini
 
Introduction to unit testing in python
Anirudh
 
NUnit Features Presentation
Shir Brass
 
Unit testing.pptx [repaired]
Mohammad Asmar
 
Intro to junit
Rakesh Srivastava
 
White box testing
Mani Kanth
 
Unit 4 testing
TharuniDiddekunta
 
Testing Philosphies
Rob Kaufman
 
New Features Of Test Unit 2.x
djberg96
 
Unit Testing with Python
MicroPyramid .
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Jacinto Limjap
 
ScioTalks | Coverage Based Testing
Scio Consulting
 
RandomTest - Random Software Integration Tests That Just Work for C/C++, Java...
dcieslak
 
Black box testing
Abdul Basit
 
Equivalence class testing
Mani Kanth
 
Software Testing Foundations Part 4 - Black Box Testing
Nikita Knysh
 
H testing and debugging
missstevenson01
 
Unit Testing
Hatem Al Sum
 
5 black box and grey box testing
Yisal Khan
 

Similar to PChomePay unit test basic (20)

PPTX
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
PDF
Back to basics - PHPUnit
Sebastian Marek
 
PDF
Unit testing in PHP
Chonlasith Jucksriporn
 
PDF
Systematic Unit Testing
scotchfield
 
PPTX
Unit & integration testing
Pavlo Hodysh
 
PPT
Unit Testing using PHPUnit
varuntaliyan
 
PDF
Unit Testing in WordPress
Barry Kooij
 
PDF
What Is Unit Testing A Complete Guide With Examples.pdf
Jace Reed
 
PPT
Test Driven Development with PHPUnit
Mindfire Solutions
 
PPT
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
PPTX
PHPUnit: from zero to hero
Jeremy Cook
 
PDF
Unit testing Agile OpenSpace
Andrei Savu
 
PDF
What Is Unit Testing_ A Complete Guide With Examples.pdf
Steve Wortham
 
PPTX
Test in action week 4
Yi-Huan Chan
 
PPT
Automated Unit Testing
Mike Lively
 
PPTX
Test in action week 2
Yi-Huan Chan
 
PPTX
Unit tests, a first introduction
Florian Nouri
 
PDF
Unit and integration Testing
David Berliner
 
PPS
Unit Testing
Anuj Arora
 
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
Back to basics - PHPUnit
Sebastian Marek
 
Unit testing in PHP
Chonlasith Jucksriporn
 
Systematic Unit Testing
scotchfield
 
Unit & integration testing
Pavlo Hodysh
 
Unit Testing using PHPUnit
varuntaliyan
 
Unit Testing in WordPress
Barry Kooij
 
What Is Unit Testing A Complete Guide With Examples.pdf
Jace Reed
 
Test Driven Development with PHPUnit
Mindfire Solutions
 
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
PHPUnit: from zero to hero
Jeremy Cook
 
Unit testing Agile OpenSpace
Andrei Savu
 
What Is Unit Testing_ A Complete Guide With Examples.pdf
Steve Wortham
 
Test in action week 4
Yi-Huan Chan
 
Automated Unit Testing
Mike Lively
 
Test in action week 2
Yi-Huan Chan
 
Unit tests, a first introduction
Florian Nouri
 
Unit and integration Testing
David Berliner
 
Unit Testing
Anuj Arora
 
Ad

Recently uploaded (20)

PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Ad

PChomePay unit test basic

  • 1. Unit Test example by PHPUnit Eric G 2019
  • 2. What is a unit test ? A unit test is a piece of code that invokes a unit of work and checks one specific end result of that unit of work. If the assumptions on the end result turn out to be wrong, the unit test has failed. A unit test’s scope can span as little as a method or as much as multiple classes.
  • 3. How you test right now ? AuthService
 .login {
 …
 }
  • 4. What are problems in previous case?
  • 5. • It’s considered an integration test • It’s redundant for many test cases • Must test every cases after modifying the code in the same unit • Other team members don’t know how to test it
  • 6. What makes a good unit test • It should be automated and repeatable • It should be easy to implement • It should be relevant tomorrow • Anyone should be able to run it at the push of a button • It should be run quickly • It should be consistent in its results (it always returns the same result if you don’t change anything between runs) • It should have full control of the unit under test • It should be fully isolated (runs independently of other tests) • When it fails, it should be easy to detect what was expected and determine how to pinpoint the problem Art of unit testing 2nd(1.2 Properties of a good unit test). Roy Osherove
  • 7. Writing the first unit test
  • 10. Why we want to use unites framework • It can be automated and repeatable • It can be easy to implement • It can be relevant tomorrow • Anyone can be able to run it at the push of a button • It can be run quickly • It should be consistent in its results (it always returns the same result if you don’t change anything between runs) • It can have full control of the unit under test • It can be fully isolated (runs independently of other tests) • When it fails, it should be easy to detect what was expected and determine how to pinpoint the problem
  • 11. Setting PHPUnit in PHPStorm
  • 16. Demo
  • 17. Types of assertions • Return value • State changing • Object Interaction
  • 18. Important rules in unit test • AAA(Got When Then) pattern • Test naming • Single Assertion
  • 19. Setup & Teardown Art of unit testing 2nd(Figure 2.5 How NUnit calls SetUp and TearDown). Roy Osherove
  • 20. Demo