SlideShare a Scribd company logo
Automated Unit Testing   using PHPUnit, Selenium and Phing Tricode Professional Services www.tricode.nl 01-05-2008 Sander van Beek & Patrick van Dissel
“ One test is worth a thousand expert opinions” -- Bill Nye, The Science Guy
Automated Unit Testing Put Angels on Your Shoulders Unit Testing Use It Before You Build It PHPUnit Different Makes a Difference Selenium Automate, Automate, Automate Phing
Put Angels on Your Shoulders Unit Testing  is a software verification and validation method where the programmer gains confidence that individual units of source code are fit for use A  unit  is the smallest testable part of an application, e.g. a  method Unit testing is  regression testing , making sure made changes are not a step backwards
Unit Testing Without Unit Testing: You write code and stick in some print statements to see the value of a few key variables. You run the code, maybe in a debug mode, and look at the results manually, fix problems that come up  Then you throw away the print statements or exit the debug mode, and move on to the next item
Unit Testing With Unit Testing: With Unit Testing you take that familiar process and instead of throwing away debug code, you save it, and continue to run it automatically Instead of manually inspecting the interesting variables, you write code to check for specific values in specific situations
Unit Testing Benefits: Provides instant feedback Code gets exercised repeatedly. As you change and rewrite your code, test cases will check that you haven’t broken existing contracts. You can quickly identify and fix any problems Makes your code robust Testing helps you think through the behavior of the code, exercising the positive, negative and exceptional cases
Unit Testing Benefits (continued): Can be a helpful design tool Unit testing can help you achieve a pragmatic and simpler design Is a confidence booster You’ve tested your code and exercised its behavior for a variety of different conditions: this will give you the confidence when faced with new,  high pressure tasks on tight deadlines You can change anything as long as the tests stay  green !
Unit Testing Benefits (continued): Can act as probes when solving problems Tests go  red  when something is wrong. If something is wrong and tests stay  green , that means that new test-cases need to be created for that specific situation Are reliable documentation Unit tests can serve as accurate, reliable documentation  When following an easy naming-convention you can even create documentation based on unit tests
Unit Testing Benefits (continued): Are a learning aid You can write unit tests against an API to facilitate your learning. The tests not only help you understand the behavior of the API but also help you quickly find any incompatible changes that might be introduced later
Unit Testing Limitations: Public API only Unit tests are focused on the public API only! Protected and private API can be tested, but wrappers are needed to get this to work. It’s a bit more work, but advised for very important/complex methods Tests are not created and updated by themselves Creating and keeping unit tests up-to-date is not an automatic process. You must to have the discipline to create and update the tests yourself!
Unit Testing Limitations (continued): Not everything can be tested By default, unit tests are focused on testing behavior of single units. Integration, performance, GUI and user acceptance tests are not the focus or supported by unit testing alone Using unit testing in combination with other testing tools can extend the reach of the tests. More and more extensions are added to unit testing frameworks to support these tools
Unit Testing Some best practices: Don't assume the order in which tests within a test case run Avoid writing test cases with side effects Do not load data from hard-coded locations on a file system Keep tests in the same location as the source code Name tests properly Keep tests small and fast Test Behavior, Not Methods Apply the “Too Simple to Break” Rule Use Object-Oriented Best Practices In Your Test Cases
Use It Before You Build It PHPUnit  is a unit testing framework for PHP5 It is one of the  xUnit  family of frameworks that originated with Kent Beck's SUnit for Smalltalk Wikipedia has a nice list of unit testing frameworks: http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
PHPUnit Static Test structure
PHPUnit Runtime Test structure
PHPUnit Basic concepts of xUnit: Test fixture The set of preconditions or state needed for a test to succeed. Also known as a test context.  Test case A single test method within a test suite. The  setUp()  and  tearDown()  methods of the test suite are executed before and after each test case, respectively Assertion Evaluate the result of the test case Test suite A collection of test cases, and A collection of test suites
A simple Test Suite class  ArrayTest extends   PHPUnit_Framework_TestCase { public function  testNewArrayIsempty() { $array  =  array (); $this -> assertEquals ( 0 , count( $array )); } }
A simple Test Suite class  ArrayTest extends  PHPUnit_Framework_TestCase { protected   $fixture ; protected   function   setUp() { parent ::setUp(); $this ->fixture =  array (); } protected function   tearDown() { parent ::tearDown(); $this ->fixture = null; } public function  testNewArrayIsempty() { $this ->assertEquals( 0 , count( $this ->fixture )); } }
Writing tests A  test suite  is a class that extends from  PHPUnit_Framework_TestCase A  test case  is a method within a test suite, which: Method name starts with ‘ test ’, or Is annotated with ‘ @test ’ The  setUp()  method of a test suite can be overriden and should be used to setup the fixture.  setUp()  is called  before each  test case The  tearDown()  method of a test suite can be overriden and should be used to cleanup the fixture. tearDown()  is called  after each  test case
Executing tests DEMO From command-line From Zend Studio Generating a result report Code-coverage
Data providers class  DataTest extends  PHPUnit_Framework_TestCase { /**       *  @dataProvider provider       */ public function  testAdd( $a ,  $b ,  $c )      {          $this ->assertEquals( $c ,  $a  +  $b );      }      public function   provider()      {       return array (             array ( 0, 0, 0 )         ,  array (0, 1, 1)          ,  array (1, 0, 1)             ,  array (1, 1, 3)  // fails          );      } }
Testing exceptions class  ExceptionTest  extends  PHPUnit_Framework_TestCase {      /**       *  @expectedException InvalidArgumentException       */      public function  testException()      { throw new   InvalidArgumentException (); } } PHPUnit converts PHP errors, notices and warnings to  exceptions, respectively: PHPUnit_Framework_Error PHPUnit_Framework_Error_Notice PHPUnit_Framework_Error_Warning
Testing performance class  PerformanceTest  extends   PHPUnit_Extensions_PerformanceTestCase { public function  testPerformance()      {          $this -> setMaxRunningTime ( 2 );   // 2 seconds          sleep( 1 );   // 1 second      } }
Testing output class  OutputTest extends   PHPUnit_Extensions_OutputTestCase {      public function  testExpectFooActualFoo()      {          $this -> expectOutputString(' foo ');          print  ' foo ';      }  } PHP's Output Buffering feature is used to provide the functionality that is necessary for this
Advanced usage Code Coverage Analysis Grouping of tests @group Mark tests incomplete Mark tests skipped Behavior-Driven development stories Agile documentation --story, --tap, --testdox Test doubles Stubs and Mocks Skeleton generation from test case to class from class to test case
Documentation Want to learn more? PHPUnit pocket guide  www.phpunit.de /manual/   Testing patterns  www.xunitpatterns.com At the end you will receive: A PHPUnit Cheatsheet for version 3.3 A Unit Testing best practices document A Test-Driven-Development: Rhythm reference guide Quick reference guid
Selenium Web application automated testing suite Tricode Professional Services www.tricode.nl 24-04-2009 Sander van Beek
Selenium Selenium is a suite of tools to automate web app testing across many platforms.  Selenium... runs in many browsers and operating systems  can be controlled by many programming languages and testing frameworks.
Selenium Selenium suite has 3 main tools: Selenium IDE  Create tests Selenium RC (remote contol) Run tests in different browsers Selenium Grid Scale out, speed up
Selenium
Selenium IDE Firefox plug-in Record tests (demo) Export them to different formats HTML C# Java PHP Ruby Perl Python
Selenium IDE Commands: Actions  open, click, refresh Accessors  Get state and store it Assertions  Verify state. Have 3 modes: - assert (halt on error) - verify (generate warning on error) - waitFor (wait for condition to become true)
Selenium RC Run distributed Selenium tests on one (remote) server
Selenium RC Supported browsers: Firefox 2, 3 IE 7, 8 Safari 2, 3 Opera 8, 9 Others: partially Supported operating systems: Windows Linux OS X, Solaris Others (as long as they run supported browsers)
Selenium Grid Selenium in parallel on multiple servers (or VM’s)
Selenium Grid http://saucelabs.com/ : Selenium on EC2 TestSwarm:  http:// ejohn.org/blog/javascript -testing-does-not-scale/
Questions More info:  http://seleniumhq.org/
Phing  An automated build system based on Apache ant  Tricode Professional Services www.tricode.nl 14-12-2008 Sander van Beek
Phing PHing Is Not GNU make;  it's a project build system based on Apache Ant. You can do anything with it that you could do with a traditional build system like GNU make, and its use of simple XML build files and extensible PHP "task" classes make it an easy-to-use and highly flexible build framework. Features include file transformations (e.g. token replacement, XSLT transformation, Smarty template transformations), file system operations, interactive build support, SQL execution, CVS operations, tools for creating PEAR packages, and much more.
Phing Automated build tool Types of automated builds: On demand Scheduled (nightly build) Automated (continuous integration)
Phing Why ‘build’ PHP? Improve product quality  Eliminate redundant tasks  Minimize "bad builds"  Eliminate dependencies on key personnel  Have history of builds and releases in order to investigate issues Save time and money - because of the reasons listed above
Concepts Targets & taks The build file: build.xml Project Target1 Task1 Task2 Target2 Task1 Task2 Target3 Task1 Task2 Targets can be dependant on each other One default target (run when no task is specified on command line)
Task types Core PhingCall, input, phpeval, condition, echo, exec File system Copy, delete, move, mkdir, touch, available, resolvePath Transformation XsltTask, ReflexiveTask Packaging pearPackageTask, zipTask, tarTask, dbdeploy, ioncube
Task types Version control svnCheckout, svnExport, svnUpdate, svnLastRevision Quality assurance phpunitTask, zendCodeAnalyser, phpDocumentor, phpCodesniffer, coverageXXX, phpLint Filters Replacing, stripping comments/whitespaces, line numbering, tidy and more Easy to add new tasks
Filesets Can be used in many tasks <fileset dir=&quot;/etc&quot; > <include name=&quot;httpd/**&quot; /> <include name=&quot;php.ini&quot; /> <exclude name=“doc/**&quot; /> </fileset>  **/* <- Ant glob syntax
Property files Create environment specific builds E.g. build.properties, c ontains ‘key=value’ lines. E.g: database.user=upcpl Can be used to replace properties in source code - e.g. ${database.user} <property file=&quot;build.properties&quot; />  <reflexive> <fileset dir=“config&quot;> <include file=“config.php”/> </fileset> <filterchain> <expandproperties />  </filterchain> </reflexive>
Running phine Simply run ‘phing’ in the directory containing build.xml Optionally specify a target as the first parameter Can also be run automated, e.g. from cruisecontrol or hudson

More Related Content

What's hot (20)

PDF
Clean Unit Test Patterns
Frank Appel
 
PDF
Unit testing with JUnit
Thomas Zimmermann
 
PPTX
Junit 4.0
pallavikhandekar212
 
PDF
JUnit 5
Scott Leberknight
 
PPTX
.Net Unit Testing with Visual Studio 2010
kgayda
 
PDF
Test driven development - JUnit basics and best practices
Narendra Pathai
 
PPTX
Unit Testing Concepts and Best Practices
Derek Smith
 
PDF
Workshop unit test
Francesco Garavaglia
 
PPTX
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
Ted Vinke
 
PPT
Junit
Manav Prasad
 
PPTX
Introduction To J unit
Olga Extone
 
ODP
Embrace Unit Testing
alessiopace
 
PPS
JUnit Presentation
priya_trivedi
 
PPTX
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Thomas Weller
 
PDF
Unit testing with JUnit
Pokpitch Patcharadamrongkul
 
PPT
JUnit 4
Sunil OS
 
PPTX
Unit Testing with JUnit4 by Ravikiran Janardhana
Ravikiran J
 
PPTX
JUnit- A Unit Testing Framework
Onkar Deshpande
 
PPTX
Unit tests & TDD
Dror Helper
 
Clean Unit Test Patterns
Frank Appel
 
Unit testing with JUnit
Thomas Zimmermann
 
.Net Unit Testing with Visual Studio 2010
kgayda
 
Test driven development - JUnit basics and best practices
Narendra Pathai
 
Unit Testing Concepts and Best Practices
Derek Smith
 
Workshop unit test
Francesco Garavaglia
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
Ted Vinke
 
Introduction To J unit
Olga Extone
 
Embrace Unit Testing
alessiopace
 
JUnit Presentation
priya_trivedi
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Thomas Weller
 
Unit testing with JUnit
Pokpitch Patcharadamrongkul
 
JUnit 4
Sunil OS
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Ravikiran J
 
JUnit- A Unit Testing Framework
Onkar Deshpande
 
Unit tests & TDD
Dror Helper
 

Similar to Unit testing php-unit - phing - selenium_v2 (20)

PPTX
PHPUnit: from zero to hero
Jeremy Cook
 
PDF
Fighting Fear-Driven-Development With PHPUnit
James Fuller
 
PPTX
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
ZIP
Test
Eddie Kao
 
PPT
Test Driven Development with PHPUnit
Mindfire Solutions
 
PPTX
Test in action – week 1
Yi-Huan Chan
 
PPT
Unit testing
davidahaskins
 
PDF
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 
PPT
Unit Testing using PHPUnit
varuntaliyan
 
KEY
PHPUnit testing to Zend_Test
Michelangelo van Dam
 
PDF
Leveling Up With Unit Testing - LonghornPHP 2022
Mark Niebergall
 
KEY
Developer testing 101: Become a Testing Fanatic
LB Denker
 
KEY
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
 
PDF
Unit Testing from Setup to Deployment
Mark Niebergall
 
PDF
Test Automation
Rodrigo Paiva
 
PDF
Cursus phpunit
Nick Belhomme
 
PPTX
Test in action week 2
Yi-Huan Chan
 
PPT
Phpunit
japan_works
 
PDF
Unit testing in PHP
Lee Boynton
 
PDF
Leveling Up With Unit Testing - php[tek] 2023
Mark Niebergall
 
PHPUnit: from zero to hero
Jeremy Cook
 
Fighting Fear-Driven-Development With PHPUnit
James Fuller
 
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
Test
Eddie Kao
 
Test Driven Development with PHPUnit
Mindfire Solutions
 
Test in action – week 1
Yi-Huan Chan
 
Unit testing
davidahaskins
 
Introduction to Unit Testing with PHPUnit
Michelangelo van Dam
 
Unit Testing using PHPUnit
varuntaliyan
 
PHPUnit testing to Zend_Test
Michelangelo van Dam
 
Leveling Up With Unit Testing - LonghornPHP 2022
Mark Niebergall
 
Developer testing 101: Become a Testing Fanatic
LB Denker
 
Php Unit With Zend Framework Zendcon09
Michelangelo van Dam
 
Unit Testing from Setup to Deployment
Mark Niebergall
 
Test Automation
Rodrigo Paiva
 
Cursus phpunit
Nick Belhomme
 
Test in action week 2
Yi-Huan Chan
 
Phpunit
japan_works
 
Unit testing in PHP
Lee Boynton
 
Leveling Up With Unit Testing - php[tek] 2023
Mark Niebergall
 
Ad

More from Tricode (part of Dept) (20)

PDF
The Top Benefits of Magnolia CMS’s Inspirational Open Suite Ideology
Tricode (part of Dept)
 
PPTX
Agile QA 2017: A New Hope
Tricode (part of Dept)
 
PDF
Mobile Sensor Networks based on Smartphone devices and Web Services
Tricode (part of Dept)
 
PPTX
Keeping Your Clients Happy and Your Management Even Happier
Tricode (part of Dept)
 
PDF
Intro to JHipster
Tricode (part of Dept)
 
PDF
Porn, the leading influencer of Technology
Tricode (part of Dept)
 
PDF
De 4 belangrijkste risicofactoren van het nearshoring proces
Tricode (part of Dept)
 
PDF
Internet Addiction (Social Media Edition)
Tricode (part of Dept)
 
PPTX
Kids Can Code - an interactive IT workshop
Tricode (part of Dept)
 
PPTX
RESTful API - Best Practices
Tricode (part of Dept)
 
PDF
Deep Learning - STM 6
Tricode (part of Dept)
 
PDF
How Technology is Affecting Society - STM 6
Tricode (part of Dept)
 
ODP
Monolithic to Microservices Architecture - STM 6
Tricode (part of Dept)
 
PDF
Customers speak on Magnolia CMS
Tricode (part of Dept)
 
PDF
Quality Nearshoring met Tricode
Tricode (part of Dept)
 
PDF
AEM Digital Assets Management - What's new in 6.2?
Tricode (part of Dept)
 
PDF
10 nearshoring it trends om in 2016 te volgen
Tricode (part of Dept)
 
PDF
Tricode & Magnolia
Tricode (part of Dept)
 
PDF
Why you should use Adobe Experience Manager Mobile
Tricode (part of Dept)
 
PDF
Introducing: Tricode's Software Factory
Tricode (part of Dept)
 
The Top Benefits of Magnolia CMS’s Inspirational Open Suite Ideology
Tricode (part of Dept)
 
Agile QA 2017: A New Hope
Tricode (part of Dept)
 
Mobile Sensor Networks based on Smartphone devices and Web Services
Tricode (part of Dept)
 
Keeping Your Clients Happy and Your Management Even Happier
Tricode (part of Dept)
 
Intro to JHipster
Tricode (part of Dept)
 
Porn, the leading influencer of Technology
Tricode (part of Dept)
 
De 4 belangrijkste risicofactoren van het nearshoring proces
Tricode (part of Dept)
 
Internet Addiction (Social Media Edition)
Tricode (part of Dept)
 
Kids Can Code - an interactive IT workshop
Tricode (part of Dept)
 
RESTful API - Best Practices
Tricode (part of Dept)
 
Deep Learning - STM 6
Tricode (part of Dept)
 
How Technology is Affecting Society - STM 6
Tricode (part of Dept)
 
Monolithic to Microservices Architecture - STM 6
Tricode (part of Dept)
 
Customers speak on Magnolia CMS
Tricode (part of Dept)
 
Quality Nearshoring met Tricode
Tricode (part of Dept)
 
AEM Digital Assets Management - What's new in 6.2?
Tricode (part of Dept)
 
10 nearshoring it trends om in 2016 te volgen
Tricode (part of Dept)
 
Tricode & Magnolia
Tricode (part of Dept)
 
Why you should use Adobe Experience Manager Mobile
Tricode (part of Dept)
 
Introducing: Tricode's Software Factory
Tricode (part of Dept)
 
Ad

Unit testing php-unit - phing - selenium_v2

  • 1. Automated Unit Testing using PHPUnit, Selenium and Phing Tricode Professional Services www.tricode.nl 01-05-2008 Sander van Beek & Patrick van Dissel
  • 2. “ One test is worth a thousand expert opinions” -- Bill Nye, The Science Guy
  • 3. Automated Unit Testing Put Angels on Your Shoulders Unit Testing Use It Before You Build It PHPUnit Different Makes a Difference Selenium Automate, Automate, Automate Phing
  • 4. Put Angels on Your Shoulders Unit Testing is a software verification and validation method where the programmer gains confidence that individual units of source code are fit for use A unit is the smallest testable part of an application, e.g. a method Unit testing is regression testing , making sure made changes are not a step backwards
  • 5. Unit Testing Without Unit Testing: You write code and stick in some print statements to see the value of a few key variables. You run the code, maybe in a debug mode, and look at the results manually, fix problems that come up Then you throw away the print statements or exit the debug mode, and move on to the next item
  • 6. Unit Testing With Unit Testing: With Unit Testing you take that familiar process and instead of throwing away debug code, you save it, and continue to run it automatically Instead of manually inspecting the interesting variables, you write code to check for specific values in specific situations
  • 7. Unit Testing Benefits: Provides instant feedback Code gets exercised repeatedly. As you change and rewrite your code, test cases will check that you haven’t broken existing contracts. You can quickly identify and fix any problems Makes your code robust Testing helps you think through the behavior of the code, exercising the positive, negative and exceptional cases
  • 8. Unit Testing Benefits (continued): Can be a helpful design tool Unit testing can help you achieve a pragmatic and simpler design Is a confidence booster You’ve tested your code and exercised its behavior for a variety of different conditions: this will give you the confidence when faced with new, high pressure tasks on tight deadlines You can change anything as long as the tests stay green !
  • 9. Unit Testing Benefits (continued): Can act as probes when solving problems Tests go red when something is wrong. If something is wrong and tests stay green , that means that new test-cases need to be created for that specific situation Are reliable documentation Unit tests can serve as accurate, reliable documentation When following an easy naming-convention you can even create documentation based on unit tests
  • 10. Unit Testing Benefits (continued): Are a learning aid You can write unit tests against an API to facilitate your learning. The tests not only help you understand the behavior of the API but also help you quickly find any incompatible changes that might be introduced later
  • 11. Unit Testing Limitations: Public API only Unit tests are focused on the public API only! Protected and private API can be tested, but wrappers are needed to get this to work. It’s a bit more work, but advised for very important/complex methods Tests are not created and updated by themselves Creating and keeping unit tests up-to-date is not an automatic process. You must to have the discipline to create and update the tests yourself!
  • 12. Unit Testing Limitations (continued): Not everything can be tested By default, unit tests are focused on testing behavior of single units. Integration, performance, GUI and user acceptance tests are not the focus or supported by unit testing alone Using unit testing in combination with other testing tools can extend the reach of the tests. More and more extensions are added to unit testing frameworks to support these tools
  • 13. Unit Testing Some best practices: Don't assume the order in which tests within a test case run Avoid writing test cases with side effects Do not load data from hard-coded locations on a file system Keep tests in the same location as the source code Name tests properly Keep tests small and fast Test Behavior, Not Methods Apply the “Too Simple to Break” Rule Use Object-Oriented Best Practices In Your Test Cases
  • 14. Use It Before You Build It PHPUnit is a unit testing framework for PHP5 It is one of the xUnit family of frameworks that originated with Kent Beck's SUnit for Smalltalk Wikipedia has a nice list of unit testing frameworks: http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks
  • 15. PHPUnit Static Test structure
  • 16. PHPUnit Runtime Test structure
  • 17. PHPUnit Basic concepts of xUnit: Test fixture The set of preconditions or state needed for a test to succeed. Also known as a test context. Test case A single test method within a test suite. The setUp() and tearDown() methods of the test suite are executed before and after each test case, respectively Assertion Evaluate the result of the test case Test suite A collection of test cases, and A collection of test suites
  • 18. A simple Test Suite class ArrayTest extends PHPUnit_Framework_TestCase { public function testNewArrayIsempty() { $array = array (); $this -> assertEquals ( 0 , count( $array )); } }
  • 19. A simple Test Suite class ArrayTest extends PHPUnit_Framework_TestCase { protected $fixture ; protected function setUp() { parent ::setUp(); $this ->fixture = array (); } protected function tearDown() { parent ::tearDown(); $this ->fixture = null; } public function testNewArrayIsempty() { $this ->assertEquals( 0 , count( $this ->fixture )); } }
  • 20. Writing tests A test suite is a class that extends from PHPUnit_Framework_TestCase A test case is a method within a test suite, which: Method name starts with ‘ test ’, or Is annotated with ‘ @test ’ The setUp() method of a test suite can be overriden and should be used to setup the fixture. setUp() is called before each test case The tearDown() method of a test suite can be overriden and should be used to cleanup the fixture. tearDown() is called after each test case
  • 21. Executing tests DEMO From command-line From Zend Studio Generating a result report Code-coverage
  • 22. Data providers class  DataTest extends  PHPUnit_Framework_TestCase { /**       *  @dataProvider provider       */ public function  testAdd( $a ,  $b ,  $c )      {          $this ->assertEquals( $c ,  $a  +  $b );      }      public function   provider()      {      return array (            array ( 0, 0, 0 )        , array (0, 1, 1)         , array (1, 0, 1)            , array (1, 1, 3) // fails          );      } }
  • 23. Testing exceptions class  ExceptionTest  extends  PHPUnit_Framework_TestCase {      /**       *  @expectedException InvalidArgumentException       */      public function  testException()      { throw new InvalidArgumentException (); } } PHPUnit converts PHP errors, notices and warnings to exceptions, respectively: PHPUnit_Framework_Error PHPUnit_Framework_Error_Notice PHPUnit_Framework_Error_Warning
  • 24. Testing performance class  PerformanceTest  extends   PHPUnit_Extensions_PerformanceTestCase { public function  testPerformance()      {          $this -> setMaxRunningTime ( 2 ); // 2 seconds          sleep( 1 ); // 1 second      } }
  • 25. Testing output class  OutputTest extends   PHPUnit_Extensions_OutputTestCase {      public function  testExpectFooActualFoo()      {          $this -> expectOutputString(' foo ');          print  ' foo ';      }  } PHP's Output Buffering feature is used to provide the functionality that is necessary for this
  • 26. Advanced usage Code Coverage Analysis Grouping of tests @group Mark tests incomplete Mark tests skipped Behavior-Driven development stories Agile documentation --story, --tap, --testdox Test doubles Stubs and Mocks Skeleton generation from test case to class from class to test case
  • 27. Documentation Want to learn more? PHPUnit pocket guide www.phpunit.de /manual/ Testing patterns www.xunitpatterns.com At the end you will receive: A PHPUnit Cheatsheet for version 3.3 A Unit Testing best practices document A Test-Driven-Development: Rhythm reference guide Quick reference guid
  • 28. Selenium Web application automated testing suite Tricode Professional Services www.tricode.nl 24-04-2009 Sander van Beek
  • 29. Selenium Selenium is a suite of tools to automate web app testing across many platforms. Selenium... runs in many browsers and operating systems can be controlled by many programming languages and testing frameworks.
  • 30. Selenium Selenium suite has 3 main tools: Selenium IDE Create tests Selenium RC (remote contol) Run tests in different browsers Selenium Grid Scale out, speed up
  • 32. Selenium IDE Firefox plug-in Record tests (demo) Export them to different formats HTML C# Java PHP Ruby Perl Python
  • 33. Selenium IDE Commands: Actions open, click, refresh Accessors Get state and store it Assertions Verify state. Have 3 modes: - assert (halt on error) - verify (generate warning on error) - waitFor (wait for condition to become true)
  • 34. Selenium RC Run distributed Selenium tests on one (remote) server
  • 35. Selenium RC Supported browsers: Firefox 2, 3 IE 7, 8 Safari 2, 3 Opera 8, 9 Others: partially Supported operating systems: Windows Linux OS X, Solaris Others (as long as they run supported browsers)
  • 36. Selenium Grid Selenium in parallel on multiple servers (or VM’s)
  • 37. Selenium Grid http://saucelabs.com/ : Selenium on EC2 TestSwarm: http:// ejohn.org/blog/javascript -testing-does-not-scale/
  • 38. Questions More info: http://seleniumhq.org/
  • 39. Phing An automated build system based on Apache ant Tricode Professional Services www.tricode.nl 14-12-2008 Sander van Beek
  • 40. Phing PHing Is Not GNU make; it's a project build system based on Apache Ant. You can do anything with it that you could do with a traditional build system like GNU make, and its use of simple XML build files and extensible PHP &quot;task&quot; classes make it an easy-to-use and highly flexible build framework. Features include file transformations (e.g. token replacement, XSLT transformation, Smarty template transformations), file system operations, interactive build support, SQL execution, CVS operations, tools for creating PEAR packages, and much more.
  • 41. Phing Automated build tool Types of automated builds: On demand Scheduled (nightly build) Automated (continuous integration)
  • 42. Phing Why ‘build’ PHP? Improve product quality Eliminate redundant tasks Minimize &quot;bad builds&quot; Eliminate dependencies on key personnel Have history of builds and releases in order to investigate issues Save time and money - because of the reasons listed above
  • 43. Concepts Targets & taks The build file: build.xml Project Target1 Task1 Task2 Target2 Task1 Task2 Target3 Task1 Task2 Targets can be dependant on each other One default target (run when no task is specified on command line)
  • 44. Task types Core PhingCall, input, phpeval, condition, echo, exec File system Copy, delete, move, mkdir, touch, available, resolvePath Transformation XsltTask, ReflexiveTask Packaging pearPackageTask, zipTask, tarTask, dbdeploy, ioncube
  • 45. Task types Version control svnCheckout, svnExport, svnUpdate, svnLastRevision Quality assurance phpunitTask, zendCodeAnalyser, phpDocumentor, phpCodesniffer, coverageXXX, phpLint Filters Replacing, stripping comments/whitespaces, line numbering, tidy and more Easy to add new tasks
  • 46. Filesets Can be used in many tasks <fileset dir=&quot;/etc&quot; > <include name=&quot;httpd/**&quot; /> <include name=&quot;php.ini&quot; /> <exclude name=“doc/**&quot; /> </fileset> **/* <- Ant glob syntax
  • 47. Property files Create environment specific builds E.g. build.properties, c ontains ‘key=value’ lines. E.g: database.user=upcpl Can be used to replace properties in source code - e.g. ${database.user} <property file=&quot;build.properties&quot; /> <reflexive> <fileset dir=“config&quot;> <include file=“config.php”/> </fileset> <filterchain> <expandproperties /> </filterchain> </reflexive>
  • 48. Running phine Simply run ‘phing’ in the directory containing build.xml Optionally specify a target as the first parameter Can also be run automated, e.g. from cruisecontrol or hudson