SlideShare a Scribd company logo
Automated Unit Testing Getting Started The 2008 DC PHP Conference June 2nd, 2008
Hello! ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Automated Unit Testing ,[object Object],[object Object],[object Object],[object Object],[object Object]
Automated Unit Testing ,[object Object],[object Object],[object Object],[object Object],[object Object]
What is Unit Testing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Automated Unit Testing ,[object Object],[object Object],[object Object],[object Object],[object Object]
Why should I unit test? ,[object Object],[object Object],[object Object]
Why should I unit test? ,[object Object],[object Object],[object Object],[object Object],[object Object]
Automated Unit Testing ,[object Object],[object Object],[object Object],[object Object],[object Object]
What Should I Test? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Automated Unit Testing ,[object Object],[object Object],[object Object],[object Object],[object Object]
When do I Test? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
When do I Test? ,[object Object],[object Object],[object Object],[object Object]
Automated Unit Testing ,[object Object],[object Object],[object Object],[object Object],[object Object]
How do I Test ,[object Object],[object Object],[object Object],[object Object]
PHPUnit ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PHPUnit - Creating a Test Case <?php require_once( 'PHPUnit/Framework/TestCase.php' ); class  SubStrTest  extends  PHPUnit_Framework_TestCase {     public function  testSubstr ()     {          $this -> assertEquals ( 'o wo' ,  substr ( 'Hello world!' ,  4 ,  4 ));     } } ?>
PHPUnit - Fixtures ,[object Object],[object Object],[object Object],[object Object]
PHPUnit - Call Order PHPUnit_Framework_TestCase::setUp(); PHPUnit_Framework_TestCase::testMyCode1(); PHPUnit_Framework_TestCase::tearDown(); PHPUnit_Framework_TestCase::setUp(); PHPUnit_Framework_TestCase::testMyCode2(); PHPUnit_Framework_TestCase::tearDown();
PHPUnit - Fixtures <?php class  BankAccountTest  extends  PHPUnit_Framework_TestCase {     protected  $ba ;     protected function  setUp ()     {          $this -> ba  = new  BankAccount ;     }     public function  testBalanceIsInitiallyZero ()     {          $this -> assertEquals ( 0 ,  $this -> ba -> getBalance ());     }     protected function  tearDown ()     {          $this -> ba  =  NULL ;     } } ?>
PHPUnit - Testing Code ,[object Object],[object Object]
PHPUnit - Testing Code <?php $this -> assertEquals ( 'o wo' ,  substr ( 'hello world' ,  4 ,  4 )); $this -> assertGreaterThan ( 3 ,  4 ); $this -> assertTrue ( TRUE ); $this -> assertNULL ( NULL ); $this -> assertContains ( 'value1' , array( 'value1' ,  'value2' ,  'value3' )); $this -> assertFileExists ( '/tmp/testfile' ); $this -> assertType ( 'int' ,  20 ); $this -> assertRegExp ( '/{3}-{2}-{4}/' ,  '123-45-6789' ); ?>
PHPUnit - Testing Code ,[object Object],[object Object],[object Object],[object Object]
PHPUnit - Testing Code <?php require_once  'PHPUnit/Framework.php' ;   class  ExceptionTest  extends  PHPUnit_Framework_TestCase {     public function  testException ()     {          $this -> setExpectedException ( 'Exception' ,  'exception message' ,  100 );     } } ?>
PHPUnit - Running a Test Usage: phpunit [switches] UnitTest [UnitTest.php]      --log-graphviz <file>  Log test execution in GraphViz markup.   --log-json <file>      Log test execution in JSON format.   --log-tap <file>       Log test execution in TAP format to file.   --log-xml <file>       Log test execution in XML format to file.   --coverage-html <dir>  Generate code coverage report in HTML format.   --coverage-xml <file>  Write code coverage information in XML format.   --test-db-dsn <dsn>    DSN for the test database.   --test-db-log-rev <r>  Revision information for database logging.   --test-db-prefix ...   Prefix that should be stripped from filenames.   --test-db-log-info ... Additional information for database logging.   --filter <pattern>     Filter which tests to run.   --group ...            Only runs tests from the specified group(s).   --exclude-group ...    Exclude tests from the specified group(s).   --loader <loader>      TestSuiteLoader implementation to use.   --repeat <times>       Runs the test(s) repeatedly.   --tap                  Report test execution progress in TAP format.   --testdox              Report test execution progress in TestDox format.
PHPUnit - Running a Test Usage: phpunit [switches] UnitTest [UnitTest.php]      --no-syntax-check      Disable syntax check of test source files.   --stop-on-failure      Stop execution upon first error or failure.   --verbose              Output more verbose information.   --wait                 Waits for a keystroke after each test.   --skeleton             Generate skeleton UnitTest class for Unit in Unit.php.   --help                 Prints this usage information.   --version              Prints the version and exits.   --configuration <file> Read configuration from XML file.   -d key[=value]         Sets a php.ini value.
PHPUnit - Test Suites ,[object Object],[object Object],[object Object],[object Object]
PHPUnit - Test Suites <?php if (! defined ( 'PHPUnit_MAIN_METHOD' ))  define ( 'PHPUnit_MAIN_METHOD' ,  'AllTests::main' ); require_once  'PHPUnit/Framework.php' ; require_once  'PHPUnit/TextUI/TestRunner.php' ; require_once  'MyTest.php' ; require_once  'MyOtherTest.php' ; class  AllTests {     public static function  main ()     {          PHPUnit_TextUI_TestRunner :: run ( self :: suite ());     }     public static function  suite ()     {          $suite  = new  PHPUnit_Framework_TestSuite ( 'My Test Suite' );          $suite -> addTestSuite ( 'MyTest' );          $suite -> addTestSuite ( 'MyOtherTest' );         return  $suite ;     } } if ( PHPUnit_MAIN_METHOD  ==  'AllTests::main' )  AllTests :: main (); ?>
PHPUnit - Test Suites ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
PHPUnit - XML Configuration Running a list of tests <phpunit>   <testsuite name=&quot;My Test Suite&quot;>     <directory suffix=&quot;Test.php&quot;>       mytests/directory     </directory>     <file>       mytests/dirtory/fileTest.php     </file>   </testsuite> </phpunit>
PHPUnit - XML Configuration ,[object Object],[object Object],[object Object]
PHPUnit - XML Configuration <?php require_once( 'PHPUnit/Framework/TestCase.php' ); class  SubStrTest  extends  PHPUnit_Framework_TestCase {      /**      * @group builtins      */      public function  testSubstr ()     {          $this -> assertEquals ( 'o wo' ,  substr ( 'Hello world!' ,  4 ,  4 ));     } } ?> >phpunit --configuration tests.xml --group builtins
PHPUnit - Annotations ,[object Object],[object Object],[object Object],[object Object],[object Object]
PHPUnit - Annotations ,[object Object],[object Object]
PHPUnit - Annotations ,[object Object],[object Object]
PHPUnit - Annotations ,[object Object],[object Object]
PHPUnit - Skeleton Generator ,[object Object],[object Object],[object Object],[object Object]
PHPUnit - Skeleton Generator ,[object Object]
PHPUnit - Skeleton Generator > phpunit --verbose CalculatorTest PHPUnit 3.2.19 by Sebastian Bergmann. CalculatorTest I Time: 0 seconds There was 1 incomplete test: 1) testAdd(CalculatorTest) This test has not been implemented yet. /home/mike/phpunit/CalculatorTest.php:65 OK, but incomplete or skipped tests! Tests: 1, Incomplete: 1.
PHPUnit - Skeleton Generator ,[object Object],[object Object]
PHPUnit - Skeleton Generator ,[object Object],[object Object]
PHPUnit - Skeleton Generator > phpunit --verbose CalculatorTest PHPUnit 3.2.19 by Sebastian Bergmann. CalculatorTest ..... Time: 0 seconds OK (5 tests)
PHPUnit - Skeleton Generator @assert (...) == X     > assertEquals(X, method(...)) @assert (...) != X     > assertNotEquals(X, method(...)) @assert (...) === X    > assertSame(X, method(...)) @assert (...) !== X    > assertNotSame(X, method(...)) @assert (...) > X      > assertGreaterThan(X, method(...)) @assert (...) >= X     > assertGreaterThanOrEqual(X, method(...)) @assert (...) < X      > assertLessThan(X, method(...)) @assert (...) <= X     > assertLessThanOrEqual(X, method(...)) @assert (...) throws X > @expectedException X
PHPUnit - Incomplete Tests TODO: finish slide
PHPUnit - Incomplete Tests Slide TODO: finish slide don't worry...just a little irony
PHPUnit - Incomplete Tests <?php require_once  'PHPUnit/Framework.php' ;   class  SampleTest  extends  PHPUnit_Framework_TestCase {     public function  testSomething ()     {          // Optional: Test anything here, if you want.          $this -> assertTrue ( TRUE ,  'This should already work.' );          // Stop here and mark this test as incomplete.          $this -> markTestIncomplete (            'This test has not been implemented yet.'          );     } } ?>
PHPUnit - SkippedTests <?php require_once  'PHPUnit/Framework.php' ;   class  DatabaseTest  extends  PHPUnit_Framework_TestCase {     protected function  setUp ()     {         if (! extension_loaded ( 'mysqli' )) {              $this -> markTestSkipped (                'The MySQLi extension is not available.'              );         }     } } ?>
Advanced Features Mock Objects Database Testing Selenium RC PHPUnderControl Come see me again! Same room, same day, 3:30 PM
Thanks http://phpun.it http://planet.phpunit.de http://digitalsandwich.com http://dev.sellingsource.com Questions???

More Related Content

What's hot

Unit test
Unit testUnit test
Unit test
Tran Duc
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practices
Narendra Pathai
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
Derek Smith
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
Valerio Maggio
 
Unit testing
Unit testingUnit testing
Unit testing
Murugesan Nataraj
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1
Kiki Ahmadi
 
J Unit
J UnitJ Unit
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Jacinto Limjap
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionAlex Su
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
alessiopace
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
GomathiNayagam S
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
Lee Englestone
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
Deepak Singhvi
 
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)
 
New Features Of Test Unit 2.x
New Features Of Test Unit 2.xNew Features Of Test Unit 2.x
New Features Of Test Unit 2.x
djberg96
 
Introduction To J unit
Introduction To J unitIntroduction To J unit
Introduction To J unitOlga Extone
 
Junit
JunitJunit

What's hot (20)

Unit test
Unit testUnit test
Unit test
 
Test driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practicesTest driven development - JUnit basics and best practices
Test driven development - JUnit basics and best practices
 
Unit test
Unit testUnit test
Unit test
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
 
Unit testing
Unit testingUnit testing
Unit testing
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1
 
J Unit
J UnitJ Unit
J Unit
 
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012Unit testing, UI testing and Test Driven Development in Visual Studio 2012
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
 
Java Unit Test and Coverage Introduction
Java Unit Test and Coverage IntroductionJava Unit Test and Coverage Introduction
Java Unit Test and Coverage Introduction
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
Unit testing, principles
Unit testing, principlesUnit testing, principles
Unit testing, principles
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
 
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
 
New Features Of Test Unit 2.x
New Features Of Test Unit 2.xNew Features Of Test Unit 2.x
New Features Of Test Unit 2.x
 
Introduction To J unit
Introduction To J unitIntroduction To J unit
Introduction To J unit
 
Junit
JunitJunit
Junit
 

Viewers also liked

Automated testing 101
Automated testing 101Automated testing 101
Automated testing 101
Tabitha Chapman
 
Real time web applications
Real time web applicationsReal time web applications
Real time web applicationsJess Chadwick
 
What you can do with WordPress Heartbeat API
What you can do with WordPress Heartbeat APIWhat you can do with WordPress Heartbeat API
What you can do with WordPress Heartbeat API
Tabitha Chapman
 
Automated Testing & Auto Scaling your Apps with Microsoft & Open Source Techn...
Automated Testing & Auto Scaling your Apps with Microsoft & Open Source Techn...Automated Testing & Auto Scaling your Apps with Microsoft & Open Source Techn...
Automated Testing & Auto Scaling your Apps with Microsoft & Open Source Techn...
Pranav Ainavolu
 
Advanced automated visual testing with Selenium
Advanced automated visual testing with SeleniumAdvanced automated visual testing with Selenium
Advanced automated visual testing with Selenium
adamcarmi
 
Selenium Based Visual Test Automation
Selenium Based Visual Test AutomationSelenium Based Visual Test Automation
Selenium Based Visual Test Automation
adamcarmi
 
Testing as a container
Testing as a containerTesting as a container
Testing as a container
Irfan Ahmad
 
How to level-up your Selenium tests with Visual Testing #SeleniumCamp
How to level-up your Selenium tests with Visual Testing #SeleniumCampHow to level-up your Selenium tests with Visual Testing #SeleniumCamp
How to level-up your Selenium tests with Visual Testing #SeleniumCamp
moshemilman
 
Automated Testing Environment by Bugzilla, Testopia and Jenkins
Automated Testing Environment by Bugzilla, Testopia and JenkinsAutomated Testing Environment by Bugzilla, Testopia and Jenkins
Automated Testing Environment by Bugzilla, Testopia and Jenkins
walkerchang
 
SeConf2015: Advanced Automated Visual Testing With Selenium
SeConf2015: Advanced Automated Visual Testing With SeleniumSeConf2015: Advanced Automated Visual Testing With Selenium
SeConf2015: Advanced Automated Visual Testing With Selenium
adamcarmi
 
Continuous Automated Testing - Cast conference workshop august 2014
Continuous Automated Testing - Cast conference workshop august 2014Continuous Automated Testing - Cast conference workshop august 2014
Continuous Automated Testing - Cast conference workshop august 2014
Noah Sussman
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with Agile
Ken McCorkell
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 
Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++
Lars Thorup
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
qooxdoo
 
Automated Regression Testing for Embedded Systems in Action
Automated Regression Testing for Embedded Systems in ActionAutomated Regression Testing for Embedded Systems in Action
Automated Regression Testing for Embedded Systems in Action
AANDTech
 
Agile Testing Framework - The Art of Automated Testing
Agile Testing Framework - The Art of Automated TestingAgile Testing Framework - The Art of Automated Testing
Agile Testing Framework - The Art of Automated Testing
Dimitri Ponomareff
 
BMW Case Study Analysis
BMW Case Study AnalysisBMW Case Study Analysis
BMW Case Study Analysis
Victoria Gnatoka
 

Viewers also liked (19)

Automated testing 101
Automated testing 101Automated testing 101
Automated testing 101
 
Real time web applications
Real time web applicationsReal time web applications
Real time web applications
 
What you can do with WordPress Heartbeat API
What you can do with WordPress Heartbeat APIWhat you can do with WordPress Heartbeat API
What you can do with WordPress Heartbeat API
 
Automated Testing & Auto Scaling your Apps with Microsoft & Open Source Techn...
Automated Testing & Auto Scaling your Apps with Microsoft & Open Source Techn...Automated Testing & Auto Scaling your Apps with Microsoft & Open Source Techn...
Automated Testing & Auto Scaling your Apps with Microsoft & Open Source Techn...
 
Advanced automated visual testing with Selenium
Advanced automated visual testing with SeleniumAdvanced automated visual testing with Selenium
Advanced automated visual testing with Selenium
 
Selenium Based Visual Test Automation
Selenium Based Visual Test AutomationSelenium Based Visual Test Automation
Selenium Based Visual Test Automation
 
Testing as a container
Testing as a containerTesting as a container
Testing as a container
 
How to level-up your Selenium tests with Visual Testing #SeleniumCamp
How to level-up your Selenium tests with Visual Testing #SeleniumCampHow to level-up your Selenium tests with Visual Testing #SeleniumCamp
How to level-up your Selenium tests with Visual Testing #SeleniumCamp
 
Automated Testing Environment by Bugzilla, Testopia and Jenkins
Automated Testing Environment by Bugzilla, Testopia and JenkinsAutomated Testing Environment by Bugzilla, Testopia and Jenkins
Automated Testing Environment by Bugzilla, Testopia and Jenkins
 
SeConf2015: Advanced Automated Visual Testing With Selenium
SeConf2015: Advanced Automated Visual Testing With SeleniumSeConf2015: Advanced Automated Visual Testing With Selenium
SeConf2015: Advanced Automated Visual Testing With Selenium
 
Continuous Automated Testing - Cast conference workshop august 2014
Continuous Automated Testing - Cast conference workshop august 2014Continuous Automated Testing - Cast conference workshop august 2014
Continuous Automated Testing - Cast conference workshop august 2014
 
Automated Testing with Agile
Automated Testing with AgileAutomated Testing with Agile
Automated Testing with Agile
 
Introduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnitIntroduction to Unit Testing with PHPUnit
Introduction to Unit Testing with PHPUnit
 
Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++Automated Testing for Embedded Software in C or C++
Automated Testing for Embedded Software in C or C++
 
Selenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web ApplicationsSelenium RC: Automated Testing of Modern Web Applications
Selenium RC: Automated Testing of Modern Web Applications
 
Automated Regression Testing for Embedded Systems in Action
Automated Regression Testing for Embedded Systems in ActionAutomated Regression Testing for Embedded Systems in Action
Automated Regression Testing for Embedded Systems in Action
 
Agile Testing Framework - The Art of Automated Testing
Agile Testing Framework - The Art of Automated TestingAgile Testing Framework - The Art of Automated Testing
Agile Testing Framework - The Art of Automated Testing
 
BMW Case Study Analysis
BMW Case Study AnalysisBMW Case Study Analysis
BMW Case Study Analysis
 
Automated Testing
Automated TestingAutomated Testing
Automated Testing
 

Similar to Automated Unit Testing

Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
James Fuller
 
Unit testing
Unit testingUnit testing
Unit testing
Arthur Purnama
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
Mindfire Solutions
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
Thanh Robi
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
Harshad Mane
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1
Albert Rosa
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnitvaruntaliyan
 
Unit Testing in PHP
Unit Testing in PHPUnit Testing in PHP
Unit Testing in PHP
Radu Murzea
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
Peter Arato
 
PHPUnit
PHPUnitPHPUnit
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2Yi-Huan Chan
 
PHPUnit with CakePHP and Yii
PHPUnit with CakePHP and YiiPHPUnit with CakePHP and Yii
PHPUnit with CakePHP and Yii
madhavi Ghadge
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
Phpunit
PhpunitPhpunit
Phpunit
japan_works
 
Test
TestTest
Test
Eddie Kao
 
Php tests tips
Php tests tipsPhp tests tips
Php tests tips
Damian Sromek
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
Jeremy Cook
 
Unit testing
Unit testingUnit testing
Unit testing
davidahaskins
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
Michelangelo van Dam
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps
Venkata Ramana
 

Similar to Automated Unit Testing (20)

Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1
 
Unit Testing using PHPUnit
Unit Testing using  PHPUnitUnit Testing using  PHPUnit
Unit Testing using PHPUnit
 
Unit Testing in PHP
Unit Testing in PHPUnit Testing in PHP
Unit Testing in PHP
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 
Test in action week 2
Test in action   week 2Test in action   week 2
Test in action week 2
 
PHPUnit with CakePHP and Yii
PHPUnit with CakePHP and YiiPHPUnit with CakePHP and Yii
PHPUnit with CakePHP and Yii
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
 
Phpunit
PhpunitPhpunit
Phpunit
 
Test
TestTest
Test
 
Php tests tips
Php tests tipsPhp tests tips
Php tests tips
 
PHPUnit: from zero to hero
PHPUnit: from zero to heroPHPUnit: from zero to hero
PHPUnit: from zero to hero
 
Unit testing
Unit testingUnit testing
Unit testing
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps
 

Recently uploaded

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

Automated Unit Testing

  • 1. Automated Unit Testing Getting Started The 2008 DC PHP Conference June 2nd, 2008
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17. PHPUnit - Creating a Test Case <?php require_once( 'PHPUnit/Framework/TestCase.php' ); class  SubStrTest  extends  PHPUnit_Framework_TestCase {     public function  testSubstr ()     {          $this -> assertEquals ( 'o wo' ,  substr ( 'Hello world!' ,  4 ,  4 ));     } } ?>
  • 18.
  • 19. PHPUnit - Call Order PHPUnit_Framework_TestCase::setUp(); PHPUnit_Framework_TestCase::testMyCode1(); PHPUnit_Framework_TestCase::tearDown(); PHPUnit_Framework_TestCase::setUp(); PHPUnit_Framework_TestCase::testMyCode2(); PHPUnit_Framework_TestCase::tearDown();
  • 20. PHPUnit - Fixtures <?php class  BankAccountTest  extends  PHPUnit_Framework_TestCase {     protected  $ba ;     protected function  setUp ()     {          $this -> ba  = new  BankAccount ;     }     public function  testBalanceIsInitiallyZero ()     {          $this -> assertEquals ( 0 ,  $this -> ba -> getBalance ());     }     protected function  tearDown ()     {          $this -> ba  =  NULL ;     } } ?>
  • 21.
  • 22. PHPUnit - Testing Code <?php $this -> assertEquals ( 'o wo' ,  substr ( 'hello world' ,  4 ,  4 )); $this -> assertGreaterThan ( 3 ,  4 ); $this -> assertTrue ( TRUE ); $this -> assertNULL ( NULL ); $this -> assertContains ( 'value1' , array( 'value1' ,  'value2' ,  'value3' )); $this -> assertFileExists ( '/tmp/testfile' ); $this -> assertType ( 'int' ,  20 ); $this -> assertRegExp ( '/{3}-{2}-{4}/' ,  '123-45-6789' ); ?>
  • 23.
  • 24. PHPUnit - Testing Code <?php require_once  'PHPUnit/Framework.php' ;   class  ExceptionTest  extends  PHPUnit_Framework_TestCase {     public function  testException ()     {          $this -> setExpectedException ( 'Exception' ,  'exception message' ,  100 );     } } ?>
  • 25. PHPUnit - Running a Test Usage: phpunit [switches] UnitTest [UnitTest.php]     --log-graphviz <file>  Log test execution in GraphViz markup.   --log-json <file>      Log test execution in JSON format.   --log-tap <file>       Log test execution in TAP format to file.   --log-xml <file>       Log test execution in XML format to file.   --coverage-html <dir>  Generate code coverage report in HTML format.   --coverage-xml <file>  Write code coverage information in XML format.   --test-db-dsn <dsn>    DSN for the test database.   --test-db-log-rev <r>  Revision information for database logging.   --test-db-prefix ...   Prefix that should be stripped from filenames.   --test-db-log-info ... Additional information for database logging.   --filter <pattern>     Filter which tests to run.   --group ...            Only runs tests from the specified group(s).   --exclude-group ...    Exclude tests from the specified group(s).   --loader <loader>      TestSuiteLoader implementation to use.   --repeat <times>       Runs the test(s) repeatedly.   --tap                  Report test execution progress in TAP format.   --testdox              Report test execution progress in TestDox format.
  • 26. PHPUnit - Running a Test Usage: phpunit [switches] UnitTest [UnitTest.php]     --no-syntax-check      Disable syntax check of test source files.   --stop-on-failure      Stop execution upon first error or failure.   --verbose              Output more verbose information.   --wait                 Waits for a keystroke after each test.   --skeleton             Generate skeleton UnitTest class for Unit in Unit.php.   --help                 Prints this usage information.   --version              Prints the version and exits.   --configuration <file> Read configuration from XML file.   -d key[=value]         Sets a php.ini value.
  • 27.
  • 28. PHPUnit - Test Suites <?php if (! defined ( 'PHPUnit_MAIN_METHOD' ))  define ( 'PHPUnit_MAIN_METHOD' ,  'AllTests::main' ); require_once  'PHPUnit/Framework.php' ; require_once  'PHPUnit/TextUI/TestRunner.php' ; require_once  'MyTest.php' ; require_once  'MyOtherTest.php' ; class  AllTests {     public static function  main ()     {          PHPUnit_TextUI_TestRunner :: run ( self :: suite ());     }     public static function  suite ()     {          $suite  = new  PHPUnit_Framework_TestSuite ( 'My Test Suite' );         $suite -> addTestSuite ( 'MyTest' );          $suite -> addTestSuite ( 'MyOtherTest' );         return  $suite ;     } } if ( PHPUnit_MAIN_METHOD  ==  'AllTests::main' ) AllTests :: main (); ?>
  • 29.
  • 30. PHPUnit - XML Configuration Running a list of tests <phpunit>   <testsuite name=&quot;My Test Suite&quot;>     <directory suffix=&quot;Test.php&quot;>       mytests/directory     </directory>     <file>       mytests/dirtory/fileTest.php     </file>   </testsuite> </phpunit>
  • 31.
  • 32. PHPUnit - XML Configuration <?php require_once( 'PHPUnit/Framework/TestCase.php' ); class  SubStrTest  extends  PHPUnit_Framework_TestCase {      /**      * @group builtins      */      public function  testSubstr ()     {          $this -> assertEquals ( 'o wo' ,  substr ( 'Hello world!' ,  4 ,  4 ));     } } ?> >phpunit --configuration tests.xml --group builtins
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39. PHPUnit - Skeleton Generator > phpunit --verbose CalculatorTest PHPUnit 3.2.19 by Sebastian Bergmann. CalculatorTest I Time: 0 seconds There was 1 incomplete test: 1) testAdd(CalculatorTest) This test has not been implemented yet. /home/mike/phpunit/CalculatorTest.php:65 OK, but incomplete or skipped tests! Tests: 1, Incomplete: 1.
  • 40.
  • 41.
  • 42. PHPUnit - Skeleton Generator > phpunit --verbose CalculatorTest PHPUnit 3.2.19 by Sebastian Bergmann. CalculatorTest ..... Time: 0 seconds OK (5 tests)
  • 43. PHPUnit - Skeleton Generator @assert (...) == X     > assertEquals(X, method(...)) @assert (...) != X     > assertNotEquals(X, method(...)) @assert (...) === X    > assertSame(X, method(...)) @assert (...) !== X    > assertNotSame(X, method(...)) @assert (...) > X      > assertGreaterThan(X, method(...)) @assert (...) >= X     > assertGreaterThanOrEqual(X, method(...)) @assert (...) < X      > assertLessThan(X, method(...)) @assert (...) <= X     > assertLessThanOrEqual(X, method(...)) @assert (...) throws X > @expectedException X
  • 44. PHPUnit - Incomplete Tests TODO: finish slide
  • 45. PHPUnit - Incomplete Tests Slide TODO: finish slide don't worry...just a little irony
  • 46. PHPUnit - Incomplete Tests <?php require_once  'PHPUnit/Framework.php' ;   class  SampleTest  extends  PHPUnit_Framework_TestCase {     public function  testSomething ()     {          // Optional: Test anything here, if you want.          $this -> assertTrue ( TRUE ,  'This should already work.' );          // Stop here and mark this test as incomplete.          $this -> markTestIncomplete (            'This test has not been implemented yet.'          );     } } ?>
  • 47. PHPUnit - SkippedTests <?php require_once  'PHPUnit/Framework.php' ;   class  DatabaseTest  extends  PHPUnit_Framework_TestCase {     protected function  setUp ()     {         if (! extension_loaded ( 'mysqli' )) {              $this -> markTestSkipped (                'The MySQLi extension is not available.'              );         }     } } ?>
  • 48. Advanced Features Mock Objects Database Testing Selenium RC PHPUnderControl Come see me again! Same room, same day, 3:30 PM
  • 49. Thanks http://phpun.it http://planet.phpunit.de http://digitalsandwich.com http://dev.sellingsource.com Questions???