This document outlines an agenda for presenting on software testing. It discusses the importance of testing code, different types of tests like unit tests, integration tests and acceptance tests. It also introduces the PHPUnit testing framework and how to write tests in PHPUnit. Specific techniques like test doubles and test-driven development are explained. Frameworks for testing code in Zend and CakePHP are also briefly mentioned.
7. Agenda
• Something about Test
what? why? why not and how to....
• Test in action!
Test tools introduction, installation and real
coding practice.
8. Agenda
• Something about Test
what? why? why not and how to....
• Test in action!
Test tools introduction, installation and real
coding practice.
Unit test, Integration test and Acceptance test.
9. Agenda
• Something about Test
what? why? why not and how to....
• Test in action!
Test tools introduction, installation and real
coding practice.
Unit test, Integration test and Acceptance test.
• Test in PHP Frameworks
10. Agenda
• Something about Test
what? why? why not and how to....
• Test in action!
Test tools introduction, installation and real
coding practice.
Unit test, Integration test and Acceptance test.
• Test in PHP Frameworks
Zend Framework(still working...)
11. Agenda
• Something about Test
what? why? why not and how to....
• Test in action!
Test tools introduction, installation and real
coding practice.
Unit test, Integration test and Acceptance test.
• Test in PHP Frameworks
Zend Framework(still working...)
CakePHP(still working...)
22. Advantages
• The sooner you test for a mistake, the
greater your chance of finding it and the
less it will cost to find and fix.
23. Advantages
• The sooner you test for a mistake, the
greater your chance of finding it and the
less it will cost to find and fix.
• Good software quality.
24. Advantages
• The sooner you test for a mistake, the
greater your chance of finding it and the
less it will cost to find and fix.
• Good software quality.
• More confidence in your product(code)!
27. Unit Test
• Verify the individual units of source code are
working properly.
28. Unit Test
• Verify the individual units of source code are
working properly.
• A unit is the smallest testable part of an
application.
29. Unit Test
• Verify the individual units of source code are
working properly.
• A unit is the smallest testable part of an
application.
• May belong to a base/super class, abstract
class or derived/child class.
52. PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
1. download source
53. PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
1. download source
2. extract and put library in include_path
54. PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
1. download source
2. extract and put library in include_path
3. minor modifications:
55. PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
1. download source
2. extract and put library in include_path
3. minor modifications:
CLI : phpunit
56. PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
1. download source
2. extract and put library in include_path
3. minor modifications:
CLI : phpunit
utils/fileloader.php
60. Conventions
• Function test*() without arguments
ex: testArray(), testmyfunction()
• Define in docblock:
ex: @test
• Test functions have to be PUBLIC
70. And....vise versa
• Generate a class skeleton from test case
classes.
• Usage:
phpunit --skeleton-class classname(.php)
71. And....vise versa
• Generate a class skeleton from test case
classes.
• Usage:
phpunit --skeleton-class classname(.php)
• Test-Driven Developement.
81. Unit Test
<?php
require_once 'PHPUnit/Framework.php';
require_once 'testcal.php';
class testcalTest extends PHPUnit_Framework_TestCase
{
protected $object;
protected function setUp()
{
$this->object = new testcal;
}
public function testAdd()
{
$this->assertEquals(2, $this->object->add(1, 1));
}
}
90. Test Double
• When some other components cannot be used in
the test environment...
91. Test Double
• When some other components cannot be used in
the test environment...
• The Test Double doesn't have to behave exactly
like the real components; it merely has to provide
the same API as the real one so that just let the
test procedure thinks it is the real one!
94. Selenium RC
• Selenium Remote-Control(RC) is a test
tool that allows you to write automated
user-interface tests for web applications in
any programming language against any
HTTP website using any mainstream
browser.
95. Selenium RC
• Selenium Remote-Control(RC) is a test
tool that allows you to write automated
user-interface tests for web applications in
any programming language against any
HTTP website using any mainstream
browser.
• More infomation:
http://seleniumhq.org
108. Test for
Zend Framework
• Application Login TestCase Example.
• Test Case:
The login page should contain one login form
and be displayed to non-authenticated users.
When a user logs in, they should be redirected
to their profile page, and that profile page
should show relevant information.
112. References
• Manual:
• PHPUnit Manual V3.3
• Articles:
• PHPUnit:
• An Introduction to the Art of Unit Testing in PHP
• Check your PHP code at every level with unit tests
• Acceptance Testing of Web Applications with PHP
• Zend Framework:
• Zend_Test_PHPUnit