Connecting Tech Pros Worldwide Forums | Help | Site Map

How to test Procedural code using "PHPUnit" Framework?

Newbie
 
Join Date: Mar 2007
Posts: 18
#1: Sep 27 '07
Hi All,

I have written some PHPUnit test code by using classes.
test.php
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. require_once('PHPUnit/Framework.php');
  4. include("hello.php");
  5.  class Test1 extends  PHPUnit_Framework_TestCase
  6.  {
  7.  
  8.         function testAdd() {
  9.             $a=3;
  10.             $b=6;
  11.              $r=add($a,$b);
  12.             $this->assertNotNull($r);
  13.             $this->assertEquals($r,9);
  14.             $this->assertTrue($r>0);
  15.         }
  16. }
  17. ?>
  18.  
hello.php
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.   function add($a,$b)
  4.  {
  5.       return ($a+$b);
  6. }
  7. ?>
  8.  
Here I am able to test whether the function is returning the expected value for the given input paramaters or not.

But, How to test the code inside the function "add()".

I mean, the testing should be done to the php code (for example:- for loops, if conditions etc.) present inside the "add()" function body.

Pl. do reply me.
Reply


Similar PHP bytes