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

Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testingikhwanhayat
 
TESTING LIFE CYCLE PPT
TESTING LIFE CYCLE PPTTESTING LIFE CYCLE PPT
TESTING LIFE CYCLE PPTsuhasreddy1
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-conceptsmedsherb
 
Manual testing concepts course 1
Manual testing concepts course 1Manual testing concepts course 1
Manual testing concepts course 1Raghu Kiran
 
Software Testing Fundamentals
Software Testing FundamentalsSoftware Testing Fundamentals
Software Testing FundamentalsChankey Pathak
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test PresentationSayedur Rahman
 
Test Driven Development (TDD)
Test Driven Development (TDD)Test Driven Development (TDD)
Test Driven Development (TDD)David Ehringer
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with AgileKen McCorkell
 
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
 

What's hot (20)

Software Testing or Quality Assurance
Software Testing or Quality AssuranceSoftware Testing or Quality Assurance
Software Testing or Quality Assurance
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
TESTING LIFE CYCLE PPT
TESTING LIFE CYCLE PPTTESTING LIFE CYCLE PPT
TESTING LIFE CYCLE PPT
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
 
Manual testing concepts course 1
Manual testing concepts course 1Manual testing concepts course 1
Manual testing concepts course 1
 
Software Testing Fundamentals
Software Testing FundamentalsSoftware Testing Fundamentals
Software Testing Fundamentals
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Software testing
Software testingSoftware testing
Software testing
 
Unit testing
Unit testing Unit testing
Unit testing
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
 
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 in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Software testing
Software testingSoftware testing
Software testing
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
Unit testing
Unit testingUnit testing
Unit testing
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with Agile
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
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
 

Similar to Unit and integration Testing

An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development CodeOps Technologies LLP
 
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
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testingAdam Stephensen
 

Similar to Unit and integration Testing (20)

An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
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
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 

Recently uploaded

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
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
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
%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
 
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
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
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
 
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
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 

Recently uploaded (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
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 🔝✔️✔️
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
%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
 
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
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
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 🔝✔️✔️
 
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
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 

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