TEST
TEST




presented by eddie
    2009.1.15
Agenda
Agenda
• Something about Test
Agenda
• Something about Test
    what? why? why not and how to....
Agenda
• Something about Test
    what? why? why not and how to....
• Test in action!
Agenda
• Something about Test
    what? why? why not and how to....
• Test in action!
    Test tools introduction, install...
Agenda
• Something about Test
    what? why? why not and how to....
• Test in action!
    Test tools introduction, install...
Agenda
• Something about Test
    what? why? why not and how to....
• Test in action!
    Test tools introduction, install...
Agenda
• Something about Test
    what? why? why not and how to....
• Test in action!
    Test tools introduction, install...
Agenda
• Something about Test
    what? why? why not and how to....
• Test in action!
    Test tools introduction, install...
What’s Test?
Test != Debug
Why Test?
Every Programmers
 Makes Mistakes!!
Why Not Test?
Why not Test?
Why not Test?
• No Time!
Why not Test?
• No Time!
• Boring!
Why not Test?
• No Time!
• Boring!
• Hey! I’m an experienced programmer!
Advantages
Advantages
• The sooner you test for a mistake, the
  greater your chance of finding it and the
  less it will cost to find ...
Advantages
• The sooner you test for a mistake, the
  greater your chance of finding it and the
  less it will cost to find ...
Advantages
• The sooner you test for a mistake, the
  greater your chance of finding it and the
  less it will cost to find ...
Then....
What’s the problem?
Unit Test
Unit Test
• Verify the individual units of source code are
  working properly.
Unit Test
• Verify the individual units of source code are
  working properly.
• A unit is the smallest testable part of a...
Unit Test
• Verify the individual units of source code are
  working properly.
• A unit is the smallest testable part of a...
Integration Test
Integration Test
• Verify high level components of the
  application work as expected.
Integration Test
• Verify high level components of the
  application work as expected.
• Use mocks, stubs and specialised ...
Acceptance Test
Acceptance Test
• Aka “Functional Test”
Acceptance Test
• Aka “Functional Test”
• Ensures that an application behaves as
  expected by the client.
Tools
Test Tools
Test Tools
• PHPUnit(Modelled after JUnit)
Test Tools
• PHPUnit(Modelled after JUnit)
• Selenium Remote-Control
PHPUnit
PHPUnit
• Requirements
PHPUnit
• Requirements
 • PHP 5.1.4 (or greater) is required, PHP 5.2 is
    recommended. PHPUnit 4 will require PHP 5.3.
PHPUnit
• Requirements
 • PHP 5.1.4 (or greater) is required, PHP 5.2 is
    recommended. PHPUnit 4 will require PHP 5.3.
...
How to Test?
How to Test?
• Setup
How to Test?
• Setup
• Execute
How to Test?
• Setup
• Execute
• Verify
How to Test?
• Setup
• Execute
• Verify
• Teardown
PHPUnit Install
PHPUnit Install
• Install from PEAR or manual installation.
PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
  1. download source
PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
  1. download source
  2. extract and p...
PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
  1. download source
  2. extract and p...
PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
  1. download source
  2. extract and p...
PHPUnit Install
• Install from PEAR or manual installation.
• Manual installation:
  1. download source
  2. extract and p...
Conventions
Conventions
• Function test*() without arguments
  ex: testArray(), testmyfunction()
Conventions
• Function test*() without arguments
  ex: testArray(), testmyfunction()
• Define in docblock:
  ex: @test
Conventions
• Function test*() without arguments
  ex: testArray(), testmyfunction()
• Define in docblock:
  ex: @test
• Te...
Remember!!
Remember!!
Comments(docblock) are MEANINGFUL !
Assert Method
Assert Method
They are methods for automatically checking
values and reporting discrepancies.
Test Skeleton
 Generator
Test Skeleton
          Generator
• Generate a test class file from classes.
Test Skeleton
          Generator
• Generate a test class file from classes.
• Usage:
  phpunit --skeleton-test testname(.p...
And....vise versa
And....vise versa
• Generate a class skeleton from test case
  classes.
And....vise versa
• Generate a class skeleton from test case
  classes.
• Usage:
  phpunit --skeleton-class classname(.php)
And....vise versa
• Generate a class skeleton from test case
  classes.
• Usage:
  phpunit --skeleton-class classname(.php...
Test Case Extensions
Test Case Extensions
• Tests for Output
Test Case Extensions
• Tests for Output
• Tests for Performance
Test Case Extensions
• Tests for Output
• Tests for Performance
• Tests for Database
Not finish yet...
Not finish yet...
• Incompleted Tests
Not finish yet...
• Incompleted Tests
• Skip Tests
Unit Test
Unit Test
Unit Test
<?php
require_once 'PHPUnit/Framework.php';
require_once 'testcal.php';
class testcalTest extends PHPUnit_Framew...
Easy Way...
Easy Way...
<?php
class Calculator
{

    /**

    * @assert (0,0) == 0

    * @assert (0,1) == 1

    * @assert (1,0) == ...
Compose your Tests
Compose your Tests
• Test Function(phpunit --filter testFunc)
Compose your Tests
• Test Function(phpunit --filter testFunc)
• Test Case
Compose your Tests
• Test Function(phpunit --filter testFunc)
• Test Case
• Test Suite(setUp(), tearDown())
Integration Test
Test Double
Test Double
•   When some other components cannot be used in
    the test environment...
Test Double
•   When some other components cannot be used in
    the test environment...

•   The Test Double doesn't have...
Acceptance Test
Selenium RC
Selenium RC
• Selenium Remote-Control(RC) is a test
  tool that allows you to write automated
  user-interface tests for w...
Selenium RC
• Selenium Remote-Control(RC) is a test
  tool that allows you to write automated
  user-interface tests for w...
How it works?
How it works?
More details....
More details....
Code Coverage
Code Coverage
• phpunit --coverage-html <reportDIR>
  testClass(.php)
Code Coverage
• phpunit --coverage-html <reportDIR>
  testClass(.php)
• xdebug is required
Test-Driven
Development
Test-Driven
        Development
• Test before coding.
Test-Driven
        Development
• Test before coding.
• Well-designed architecture and APIs.
Test for
PHP Frameworks
Test for
Zend Framework
Test for
    Zend Framework
• Application Login TestCase Example.
• Test Case:
    The login page should contain one login...
Test for
CakePHP
Test for
            CakePHP
• To be Continued...
References
References
• Manual:
  •   PHPUnit Manual V3.3

• Articles:
  •   PHPUnit:
      •   An Introduction to the Art of Unit Te...
Debugging Sucks,
 Testing Rocks!
Thank you :)
Test
Test
Test
Upcoming SlideShare
Loading in...5
×

Test

1,426

Published on

Something about Test, Unit Test, Integration Test and Acceptance Test with powerful testing tools such as PHPUnit and Selenium RC.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,426
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

































































































































  • Test

    1. 1. TEST
    2. 2. TEST presented by eddie 2009.1.15
    3. 3. Agenda
    4. 4. Agenda • Something about Test
    5. 5. Agenda • Something about Test what? why? why not and how to....
    6. 6. Agenda • Something about Test what? why? why not and how to.... • Test in action!
    7. 7. Agenda • Something about Test what? why? why not and how to.... • Test in action! Test tools introduction, installation and real coding practice.
    8. 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. 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. 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. 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...)
    12. 12. What’s Test?
    13. 13. Test != Debug
    14. 14. Why Test?
    15. 15. Every Programmers Makes Mistakes!!
    16. 16. Why Not Test?
    17. 17. Why not Test?
    18. 18. Why not Test? • No Time!
    19. 19. Why not Test? • No Time! • Boring!
    20. 20. Why not Test? • No Time! • Boring! • Hey! I’m an experienced programmer!
    21. 21. Advantages
    22. 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. 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. 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)!
    25. 25. Then.... What’s the problem?
    26. 26. Unit Test
    27. 27. Unit Test • Verify the individual units of source code are working properly.
    28. 28. Unit Test • Verify the individual units of source code are working properly. • A unit is the smallest testable part of an application.
    29. 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.
    30. 30. Integration Test
    31. 31. Integration Test • Verify high level components of the application work as expected.
    32. 32. Integration Test • Verify high level components of the application work as expected. • Use mocks, stubs and specialised test classes.
    33. 33. Acceptance Test
    34. 34. Acceptance Test • Aka “Functional Test”
    35. 35. Acceptance Test • Aka “Functional Test” • Ensures that an application behaves as expected by the client.
    36. 36. Tools
    37. 37. Test Tools
    38. 38. Test Tools • PHPUnit(Modelled after JUnit)
    39. 39. Test Tools • PHPUnit(Modelled after JUnit) • Selenium Remote-Control
    40. 40. PHPUnit
    41. 41. PHPUnit • Requirements
    42. 42. PHPUnit • Requirements • PHP 5.1.4 (or greater) is required, PHP 5.2 is recommended. PHPUnit 4 will require PHP 5.3.
    43. 43. PHPUnit • Requirements • PHP 5.1.4 (or greater) is required, PHP 5.2 is recommended. PHPUnit 4 will require PHP 5.3. • more information: http://www.phpunit.de/wiki/Requirements
    44. 44. How to Test?
    45. 45. How to Test? • Setup
    46. 46. How to Test? • Setup • Execute
    47. 47. How to Test? • Setup • Execute • Verify
    48. 48. How to Test? • Setup • Execute • Verify • Teardown
    49. 49. PHPUnit Install
    50. 50. PHPUnit Install • Install from PEAR or manual installation.
    51. 51. PHPUnit Install • Install from PEAR or manual installation. • Manual installation:
    52. 52. PHPUnit Install • Install from PEAR or manual installation. • Manual installation: 1. download source
    53. 53. PHPUnit Install • Install from PEAR or manual installation. • Manual installation: 1. download source 2. extract and put library in include_path
    54. 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. 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. 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
    57. 57. Conventions
    58. 58. Conventions • Function test*() without arguments ex: testArray(), testmyfunction()
    59. 59. Conventions • Function test*() without arguments ex: testArray(), testmyfunction() • Define in docblock: ex: @test
    60. 60. Conventions • Function test*() without arguments ex: testArray(), testmyfunction() • Define in docblock: ex: @test • Test functions have to be PUBLIC
    61. 61. Remember!!
    62. 62. Remember!! Comments(docblock) are MEANINGFUL !
    63. 63. Assert Method
    64. 64. Assert Method They are methods for automatically checking values and reporting discrepancies.
    65. 65. Test Skeleton Generator
    66. 66. Test Skeleton Generator • Generate a test class file from classes.
    67. 67. Test Skeleton Generator • Generate a test class file from classes. • Usage: phpunit --skeleton-test testname(.php)
    68. 68. And....vise versa
    69. 69. And....vise versa • Generate a class skeleton from test case classes.
    70. 70. And....vise versa • Generate a class skeleton from test case classes. • Usage: phpunit --skeleton-class classname(.php)
    71. 71. And....vise versa • Generate a class skeleton from test case classes. • Usage: phpunit --skeleton-class classname(.php) • Test-Driven Developement.
    72. 72. Test Case Extensions
    73. 73. Test Case Extensions • Tests for Output
    74. 74. Test Case Extensions • Tests for Output • Tests for Performance
    75. 75. Test Case Extensions • Tests for Output • Tests for Performance • Tests for Database
    76. 76. Not finish yet...
    77. 77. Not finish yet... • Incompleted Tests
    78. 78. Not finish yet... • Incompleted Tests • Skip Tests
    79. 79. Unit Test
    80. 80. Unit Test
    81. 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)); } }
    82. 82. Easy Way...
    83. 83. Easy Way... <?php class Calculator { /** * @assert (0,0) == 0 * @assert (0,1) == 1 * @assert (1,0) == 1 * @assert (1,1) == 2 * @assert (1,2) != 3 */ public function add($a, $b) { return $a + $b; } }
    84. 84. Compose your Tests
    85. 85. Compose your Tests • Test Function(phpunit --filter testFunc)
    86. 86. Compose your Tests • Test Function(phpunit --filter testFunc) • Test Case
    87. 87. Compose your Tests • Test Function(phpunit --filter testFunc) • Test Case • Test Suite(setUp(), tearDown())
    88. 88. Integration Test
    89. 89. Test Double
    90. 90. Test Double • When some other components cannot be used in the test environment...
    91. 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!
    92. 92. Acceptance Test
    93. 93. Selenium RC
    94. 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. 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
    96. 96. How it works?
    97. 97. How it works?
    98. 98. More details....
    99. 99. More details....
    100. 100. Code Coverage
    101. 101. Code Coverage • phpunit --coverage-html <reportDIR> testClass(.php)
    102. 102. Code Coverage • phpunit --coverage-html <reportDIR> testClass(.php) • xdebug is required
    103. 103. Test-Driven Development
    104. 104. Test-Driven Development • Test before coding.
    105. 105. Test-Driven Development • Test before coding. • Well-designed architecture and APIs.
    106. 106. Test for PHP Frameworks
    107. 107. Test for Zend Framework
    108. 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.
    109. 109. Test for CakePHP
    110. 110. Test for CakePHP • To be Continued...
    111. 111. References
    112. 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
    113. 113. Debugging Sucks, Testing Rocks!
    114. 114. Thank you :)

    ×