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

Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
medsherb
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
suhasreddy1
 
Manual testing concepts course 1
Manual testing concepts course 1Manual testing concepts course 1
Manual testing concepts course 1
Raghu Kiran
 

What's hot (20)

Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Unit Testing vs Integration Testing
Unit Testing vs Integration TestingUnit Testing vs Integration Testing
Unit Testing vs Integration Testing
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Unit Testing (C#)
Unit Testing (C#)Unit Testing (C#)
Unit Testing (C#)
 
Unit testing
Unit testingUnit testing
Unit testing
 
Manual testing concepts course 1
Manual testing concepts course 1Manual testing concepts course 1
Manual testing concepts course 1
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in Angular
 
Selenium webdriver interview questions and answers
Selenium webdriver interview questions and answersSelenium webdriver interview questions and answers
Selenium webdriver interview questions and answers
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Introduction to Selenium Web Driver
Introduction to Selenium Web DriverIntroduction to Selenium Web Driver
Introduction to Selenium Web Driver
 
Introduction & Manual Testing
Introduction & Manual TestingIntroduction & Manual Testing
Introduction & Manual Testing
 
Test automation
Test automationTest automation
Test automation
 
Manual testing
Manual testingManual testing
Manual testing
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Sanity testing and smoke testing
Sanity testing and smoke testingSanity testing and smoke testing
Sanity testing and smoke 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_v2
Tricode (part of Dept)
 
TEST EXECUTION AND REPORTING
TEST EXECUTION AND REPORTINGTEST EXECUTION AND REPORTING
TEST EXECUTION AND REPORTING
suhasreddy1
 
ISTQB / ISEB Foundation Exam Practice -1
ISTQB / ISEB Foundation Exam Practice -1ISTQB / ISEB Foundation Exam Practice -1
ISTQB / ISEB Foundation Exam Practice -1
Yogindernath Gupta
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
guest268ee8
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
catherinewall
 

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
 
Unit testing
Unit testingUnit testing
Unit testing
 
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

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Recently uploaded (20)

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...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
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
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
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
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%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
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
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
 

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