SlideShare a Scribd company logo
1 of 57
Download to read offline
UNIT & 
INTEGRATION 
TESTING 
David Berliner
Why Test 
Types of Tests 
PHPUnit 
Writing Tests 
Getting Stuck In
WHY TEST?
TESTS REDUCE BUGS
TESTS REDUCE BUGS 
TESTS ARE GOOD DOCUMENTATION
TESTS REDUCE BUGS 
TESTS ARE GOOD DOCUMENTATION 
TESTS ALLOW SAFE REFACTORING
TESTS REDUCE BUGS 
TESTS ARE GOOD DOCUMENTATION 
TESTS ALLOW SAFE REFACTORING 
TESTS REDUCE THE COST OF CHANGE
TESTS REDUCE BUGS 
TESTS ARE GOOD DOCUMENTATION 
TESTS ALLOW SAFE REFACTORING 
TESTS REDUCE THE COST OF CHANGE 
TESTING FORCES YOU TO THINK
TESTS REDUCE BUGS 
TESTS ARE GOOD DOCUMENTATION 
TESTS ALLOW SAFE REFACTORING 
TESTS REDUCE THE COST OF CHANGE 
TESTING FORCES YOU TO THINK 
TESTS REDUCE FEAR
A study conducted by Microsoft and 
IBM showed that writing tests can 
add 15% – 35% to development time 
but reduce the number of bugs by 
40% – 90%. 
http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf
TYPES OF TESTS
Black Box 
White Box 
Unit 
Integration 
Functional 
System 
Regression 
Performance 
Smoke 
Canary 
Usability 
A/B 
…
Black Box 
White Box 
Unit 
Integration 
Functional 
System 
Regression 
Performance 
Smoke 
Canary 
Usability 
A/B 
…
UNIT TESTS 
The goal of unit testing is: 
1. to isolate each part of the program, and
UNIT TESTS 
The goal of unit testing is: 
1. to isolate each part of the program, and 
2. show that the individual parts are correct.
UNIT TESTS 
The goal of unit testing is: 
1. to isolate each part of the program, and 
2. show that the individual parts are correct. 
Unit tests have a very narrow and well-defined scope.
UNIT TESTS 
Pro’s: 
1. Fast
UNIT TESTS 
Pro’s: 
1. Fast 
2. Simple to understand
UNIT TESTS 
Pro’s: 
1. Fast 
2. Simple to understand 
3. Reliable
UNIT TESTS 
Pro’s: 
1. Fast 
2. Simple to understand 
3. Reliable 
Con’s: 
1. Large time investment
UNIT TESTS 
Pro’s: 
1. Fast 
2. Simple to understand 
3. Reliable 
Con’s: 
1. Large time investment 
2. Requires maintenance
UNIT TESTS 
A unit test should NOT: 
1. Access the network
UNIT TESTS 
A unit test should NOT: 
1. Access the network 
2. Hit a database
UNIT TESTS 
A unit test should NOT: 
1. Access the network 
2. Hit a database 
3. Use the file system
UNIT TESTS 
A unit test should NOT: 
1. Access the network 
2. Hit a database 
3. Use the file system 
4. Call other non-trivial components
INTEGRATION TESTS 
Test the inter-operation of multiple subsystems. 
Pro’s: 
1. Make sure nuts and bolts 
fit together
INTEGRATION TESTS 
Test the inter-operation of multiple subsystems. 
Pro’s: 
1. Make sure nuts and bolts 
fit together 
2. Test behaviour 
and infrastructure
INTEGRATION TESTS 
Test the inter-operation of multiple subsystems. 
Pro’s: 
1. Make sure nuts and bolts 
fit together 
2. Test behaviour 
and infrastructure 
3. (tested code) / test % is high
INTEGRATION TESTS 
Test the inter-operation of multiple subsystems. 
Pro’s: 
1. Make sure nuts and bolts 
fit together 
2. Test behaviour 
and infrastructure 
3. (tested code) / test % is high 
Con’s: 
1. Hard to test all critical paths
INTEGRATION TESTS 
Test the inter-operation of multiple subsystems. 
Pro’s: 
1. Make sure nuts and bolts 
fit together 
2. Test behaviour 
and infrastructure 
3. (tested code) / test % is high 
Con’s: 
1. Hard to test all critical paths 
2. Harder to localise source 
of errors
TEST HIERARCHY
PHPUnit
1. Unit Testing Framework written in PHP by Sebastian Bergmann 
2. De facto standard 
3. Major Frameworks use it (Zend, Cake, Laravel, Symphony etc.)
Installation: 
https://phpunit.de/manual/current/en/installation.html 
Be sure to install xDebug in order to generate code coverage. 
Note: PECL no longer supported
WRITING TESTS
ORGANISING TESTS 
- The tests for class Foo are placed in a class FooTest 
- Most of the time you will inherit from 
PHPUnit_Framework_TestCase 
PHPUnit_Extensions_Database_TestCase 
- Tests are public methods named test* 
- Inside the test methods, assertion methods such as 
assertEquals() are used.
ORGANISING TESTS 
Tests should mirror the code being tested. 
SRC 
SomeFolder 
Baz.php 
Foo.php 
Bar.php 
TEST 
SomeFolder 
FooTest.php 
BarTest.php 
BazTest.php
PHPUNIT.XML
BOOTSTRAP.PHP
ASSERTIONS 
assertArrayHasKey() 
assertClassHasAttribute() 
assertClassHasStaticAttribute() 
assertContains() 
assertContainsOnly() 
assertContainsOnlyInstancesOf() 
assertCount() 
assertEmpty() 
assertEqualXMLStructure() 
assertEquals() 
assertFalse() 
assertFileEquals() 
assertFileExists() 
assertGreaterThan() 
assertGreaterThanOrEqual() 
assertInstanceOf() 
assertInternalType() 
assertJsonFileEqualsJsonFile() 
assertJsonStringEqualsJsonFile() 
assertJsonStringEqualsJsonString() 
assertLessThan() 
assertLessThanOrEqual() 
assertNull ( ) 
assertObjectHasAttribute() 
assertRegExp() 
assertStringMatchesFormat() 
assertStringMatchesFormatFile() 
assertSame() 
assertStringEndsWi th() 
assertStringEqualsFile() 
assertStringStartsWi th() 
assertThat() 
assertTrue() 
assertXmlFileEqualsXmlFile() 
assertXmlStringEqualsXmlFile() 
assertXmlStringEqualsXmlString()
ASSERTIONS
ANNOTATIONS @DEPENDS
ANNOTATIONS @DATAPROVIDER
ANNOTATIONS @EXCEPTIONS
What do you do if the code you want to test 
is dependent on other components that 
cannot be used in the test environment?
MOCKS & STUBS
DATABASE TESTING 
Four stages of a DB test 
1. Set up fixture 
2. Exercise System Under Test 
3. Verify outcome 
4. Teardown
DATABASE TESTING (CONT) Give it a connection
DATABASE TESTING (CONT) Flat XML DataSet
DATABASE TESTING (CONT)
DATABASE TESTING (CONT)
GETTING STUCK IN
Demo: 
https://github.com/manatok/talk-demo-ci
• db - Database Skel file and patches 
• src - Project Code 
• test/Output - Code coverage 
• test/SportsBet - Projects Tests 
• test/TestingCore - Uti l i ties 
• tools - CI tools including ANT build 
file
Unit and integration Testing

More Related Content

What's hot (20)

Unit testing
Unit testingUnit testing
Unit testing
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
Unit testing
Unit testing Unit testing
Unit testing
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Manual testing ppt
Manual testing pptManual testing ppt
Manual testing ppt
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Unit testing
Unit testingUnit testing
Unit testing
 
Introduction to Test Automation
Introduction to Test AutomationIntroduction to Test Automation
Introduction to Test Automation
 
Agile testing
Agile testingAgile testing
Agile testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
 
Code coverage
Code coverageCode coverage
Code coverage
 
Manual testing
Manual testingManual testing
Manual testing
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 

Similar to Unit and integration Testing

Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2Tricode (part of Dept)
 
TEST EXECUTION AND REPORTING
TEST EXECUTION AND REPORTINGTEST EXECUTION AND REPORTING
TEST EXECUTION AND REPORTINGsuhasreddy1
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Mohamed Taman
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit TestingMike Lively
 
ISTQB, ISEB Lecture Notes
ISTQB, ISEB Lecture NotesISTQB, ISEB Lecture Notes
ISTQB, ISEB Lecture Notesonsoftwaretest
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitJames Fuller
 
ISTQB / ISEB Foundation Exam Practice -1
ISTQB / ISEB Foundation Exam Practice -1ISTQB / ISEB Foundation Exam Practice -1
ISTQB / ISEB Foundation Exam Practice -1Yogindernath Gupta
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Qualityguest268ee8
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTscatherinewall
 
Testing on frontend
Testing on frontendTesting on frontend
Testing on frontendAfif Alfiano
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)Steve Upton
 

Similar to Unit and integration Testing (20)

Application Testing
Application TestingApplication Testing
Application Testing
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Test execution may_04_2006
Test execution may_04_2006Test execution may_04_2006
Test execution may_04_2006
 
TEST EXECUTION AND REPORTING
TEST EXECUTION AND REPORTINGTEST EXECUTION AND REPORTING
TEST EXECUTION AND REPORTING
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Review of an open source unit test tool- Cucumber_Presentation
Review of an open source unit test tool- Cucumber_PresentationReview of an open source unit test tool- Cucumber_Presentation
Review of an open source unit test tool- Cucumber_Presentation
 
ISTQB, ISEB Lecture Notes
ISTQB, ISEB Lecture NotesISTQB, ISEB Lecture Notes
ISTQB, ISEB Lecture Notes
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
ISTQB / ISEB Foundation Exam Practice -1
ISTQB / ISEB Foundation Exam Practice -1ISTQB / ISEB Foundation Exam Practice -1
ISTQB / ISEB Foundation Exam Practice -1
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
Testing 101
Testing 101Testing 101
Testing 101
 
Testing on frontend
Testing on frontendTesting on frontend
Testing on frontend
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 

Recently uploaded

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 

Recently uploaded (20)

Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 

Unit and integration Testing

  • 1. UNIT & INTEGRATION TESTING David Berliner
  • 2. Why Test Types of Tests PHPUnit Writing Tests Getting Stuck In
  • 3.
  • 6. TESTS REDUCE BUGS TESTS ARE GOOD DOCUMENTATION
  • 7. TESTS REDUCE BUGS TESTS ARE GOOD DOCUMENTATION TESTS ALLOW SAFE REFACTORING
  • 8. TESTS REDUCE BUGS TESTS ARE GOOD DOCUMENTATION TESTS ALLOW SAFE REFACTORING TESTS REDUCE THE COST OF CHANGE
  • 9. TESTS REDUCE BUGS TESTS ARE GOOD DOCUMENTATION TESTS ALLOW SAFE REFACTORING TESTS REDUCE THE COST OF CHANGE TESTING FORCES YOU TO THINK
  • 10. TESTS REDUCE BUGS TESTS ARE GOOD DOCUMENTATION TESTS ALLOW SAFE REFACTORING TESTS REDUCE THE COST OF CHANGE TESTING FORCES YOU TO THINK TESTS REDUCE FEAR
  • 11. A study conducted by Microsoft and IBM showed that writing tests can add 15% – 35% to development time but reduce the number of bugs by 40% – 90%. http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf
  • 13. Black Box White Box Unit Integration Functional System Regression Performance Smoke Canary Usability A/B …
  • 14. Black Box White Box Unit Integration Functional System Regression Performance Smoke Canary Usability A/B …
  • 15. UNIT TESTS The goal of unit testing is: 1. to isolate each part of the program, and
  • 16. UNIT TESTS The goal of unit testing is: 1. to isolate each part of the program, and 2. show that the individual parts are correct.
  • 17. UNIT TESTS The goal of unit testing is: 1. to isolate each part of the program, and 2. show that the individual parts are correct. Unit tests have a very narrow and well-defined scope.
  • 19. UNIT TESTS Pro’s: 1. Fast 2. Simple to understand
  • 20. UNIT TESTS Pro’s: 1. Fast 2. Simple to understand 3. Reliable
  • 21. UNIT TESTS Pro’s: 1. Fast 2. Simple to understand 3. Reliable Con’s: 1. Large time investment
  • 22. UNIT TESTS Pro’s: 1. Fast 2. Simple to understand 3. Reliable Con’s: 1. Large time investment 2. Requires maintenance
  • 23. UNIT TESTS A unit test should NOT: 1. Access the network
  • 24. UNIT TESTS A unit test should NOT: 1. Access the network 2. Hit a database
  • 25. UNIT TESTS A unit test should NOT: 1. Access the network 2. Hit a database 3. Use the file system
  • 26. UNIT TESTS A unit test should NOT: 1. Access the network 2. Hit a database 3. Use the file system 4. Call other non-trivial components
  • 27. INTEGRATION TESTS Test the inter-operation of multiple subsystems. Pro’s: 1. Make sure nuts and bolts fit together
  • 28. INTEGRATION TESTS Test the inter-operation of multiple subsystems. Pro’s: 1. Make sure nuts and bolts fit together 2. Test behaviour and infrastructure
  • 29. INTEGRATION TESTS Test the inter-operation of multiple subsystems. Pro’s: 1. Make sure nuts and bolts fit together 2. Test behaviour and infrastructure 3. (tested code) / test % is high
  • 30. INTEGRATION TESTS Test the inter-operation of multiple subsystems. Pro’s: 1. Make sure nuts and bolts fit together 2. Test behaviour and infrastructure 3. (tested code) / test % is high Con’s: 1. Hard to test all critical paths
  • 31. INTEGRATION TESTS Test the inter-operation of multiple subsystems. Pro’s: 1. Make sure nuts and bolts fit together 2. Test behaviour and infrastructure 3. (tested code) / test % is high Con’s: 1. Hard to test all critical paths 2. Harder to localise source of errors
  • 33.
  • 35. 1. Unit Testing Framework written in PHP by Sebastian Bergmann 2. De facto standard 3. Major Frameworks use it (Zend, Cake, Laravel, Symphony etc.)
  • 36. Installation: https://phpunit.de/manual/current/en/installation.html Be sure to install xDebug in order to generate code coverage. Note: PECL no longer supported
  • 38. ORGANISING TESTS - The tests for class Foo are placed in a class FooTest - Most of the time you will inherit from PHPUnit_Framework_TestCase PHPUnit_Extensions_Database_TestCase - Tests are public methods named test* - Inside the test methods, assertion methods such as assertEquals() are used.
  • 39. ORGANISING TESTS Tests should mirror the code being tested. SRC SomeFolder Baz.php Foo.php Bar.php TEST SomeFolder FooTest.php BarTest.php BazTest.php
  • 42. ASSERTIONS assertArrayHasKey() assertClassHasAttribute() assertClassHasStaticAttribute() assertContains() assertContainsOnly() assertContainsOnlyInstancesOf() assertCount() assertEmpty() assertEqualXMLStructure() assertEquals() assertFalse() assertFileEquals() assertFileExists() assertGreaterThan() assertGreaterThanOrEqual() assertInstanceOf() assertInternalType() assertJsonFileEqualsJsonFile() assertJsonStringEqualsJsonFile() assertJsonStringEqualsJsonString() assertLessThan() assertLessThanOrEqual() assertNull ( ) assertObjectHasAttribute() assertRegExp() assertStringMatchesFormat() assertStringMatchesFormatFile() assertSame() assertStringEndsWi th() assertStringEqualsFile() assertStringStartsWi th() assertThat() assertTrue() assertXmlFileEqualsXmlFile() assertXmlStringEqualsXmlFile() assertXmlStringEqualsXmlString()
  • 47. What do you do if the code you want to test is dependent on other components that cannot be used in the test environment?
  • 49. DATABASE TESTING Four stages of a DB test 1. Set up fixture 2. Exercise System Under Test 3. Verify outcome 4. Teardown
  • 50. DATABASE TESTING (CONT) Give it a connection
  • 51. DATABASE TESTING (CONT) Flat XML DataSet
  • 56. • db - Database Skel file and patches • src - Project Code • test/Output - Code coverage • test/SportsBet - Projects Tests • test/TestingCore - Uti l i ties • tools - CI tools including ANT build file