phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Simple Test: Testing with Several Values (Part 2)

Tag: simple test, test unit   Category:
post: 11 Nov 2007 read: 669


After build unit test for your function, may be you are not sure one test will applicable for all cases. You can test with several static values, make sure you write right function.

You can write like following code:


<?php

define('RATE', 0.05);

function interest_per_year($amount)
{
  return round($amount * RATE, 2);
}

// Include test library
require_once 'simpletest/unit_tester.php' ;
require_once 'simpletest/reporter.php' ;

class TestingTestCase extends UnitTestCase{

  function TestingTestCase($name = '')
  {
    $this->UnitTestCase( $name );
  }
	
  function TestInterest(){
    $this->assertEqual(5, interest_per_year(100));
    $this->assertEqual(2.2, interest_per_year(73));	
  }
	
}

// run test
$test = new TestingTestCase( 'Testing Unit Test' );
$test->run(new HTMLReporter());

?>

Following image show you one test success, one test fail.



Series this article:
Simple Test: Testing Your Code (Part 1)
Simple Test: Testing with Several Values (Part 2)

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting