Back to basics




            Sebastian Marek
What is a unit test?


In computer programming, unit testing is a method by
which individual units of source code are tested to
determine if they are fit for use. A unit is the smallest
testable part of an application.
                                http://en.wikipedia.org/wiki/Unit_testing
For whom?



Unit tests are typically written and run by software
developers to ensure that code meets its design and
behaves as intended.
                           http://en.wikipedia.org/wiki/Unit_testing
What for?

The goal of unit testing is to isolate each part of the
program and show that the individual parts are correct. A
unit test provides a strict, written contract that the piece
of code must satisfy. As a result, it affords several
benefits. Unit tests find problems early in the
development cycle.
                                http://en.wikipedia.org/wiki/Unit_testing
Benefits

● Facilitates change
● Simplifies integration

● Living documentation

● Early design
Installing PHPUnit

#> pear channel-discover pear.phpunit.de
#> pear channel-discover components.ez.no
#> pear channel-discover pear.symfony-project.com

#> pear install phpunit/PHPUnit
#> phpunit –version
PHPUnit 3.5.11 by Sebastian Bergmann.
Managing tests
Writing tests

● assertions
● testing exceptions

● data providers

● test dependencies

● test fixtures

● stubs

● mock objects
Logging results

● verbose mode
● testdox format

● test results

● code coverage results
PHPUnit configuration file

● bootstrap file
● process isolation

● including and excluding files for code coverage

● logging
Resources

●   http://www.phpunit.de/manual/current/en/index.html
Q&A




?

Back to basics - PHPUnit

  • 1.
    Back to basics Sebastian Marek
  • 2.
    What is aunit test? In computer programming, unit testing is a method by which individual units of source code are tested to determine if they are fit for use. A unit is the smallest testable part of an application. http://en.wikipedia.org/wiki/Unit_testing
  • 3.
    For whom? Unit testsare typically written and run by software developers to ensure that code meets its design and behaves as intended. http://en.wikipedia.org/wiki/Unit_testing
  • 4.
    What for? The goalof unit testing is to isolate each part of the program and show that the individual parts are correct. A unit test provides a strict, written contract that the piece of code must satisfy. As a result, it affords several benefits. Unit tests find problems early in the development cycle. http://en.wikipedia.org/wiki/Unit_testing
  • 5.
    Benefits ● Facilitates change ●Simplifies integration ● Living documentation ● Early design
  • 6.
    Installing PHPUnit #> pearchannel-discover pear.phpunit.de #> pear channel-discover components.ez.no #> pear channel-discover pear.symfony-project.com #> pear install phpunit/PHPUnit #> phpunit –version PHPUnit 3.5.11 by Sebastian Bergmann.
  • 7.
  • 8.
    Writing tests ● assertions ●testing exceptions ● data providers ● test dependencies ● test fixtures ● stubs ● mock objects
  • 9.
    Logging results ● verbosemode ● testdox format ● test results ● code coverage results
  • 10.
    PHPUnit configuration file ●bootstrap file ● process isolation ● including and excluding files for code coverage ● logging
  • 11.
    Resources ● http://www.phpunit.de/manual/current/en/index.html
  • 12.