Improved Skeleton Generator in PHPUnit 3
PHPUnit can help you write your tests by analyzing the code of an existing class and generating a skeleton test-case class for it. With PHPUnit 3 this feature will be more powerful as it now supports
A
@assert annotations in the class source.A
@assert (1, 2) == 3 annotation for a method with signature add($a, $b) will generate a test method that calls add(1, 2) and expects 3 as the result.
<?php
class Calculator
{
/**
* @assert (0, 0) == 0
* @assert (0, 1) == 1
* @assert (1, 0) == 1
* @assert (1, 1) == 2
*/
public function add($a, $b)
{
return $a + $b;
}
}
?>
sb@wopr-mobile ~ % phpunit --skeleton Calculator PHPUnit 3.0.0 by Sebastian Bergmann. Wrote test class skeleton for Calculator to CalculatorTest.php.
<?php
require_once "PHPUnit/Framework/TestCase.php";
require_once "Calculator.php";
class CalculatorTest extends PHPUnit_Framework_TestCase {
/**
* Generated from @assert (0, 0) == 0.
*/
public function testAdd() {
$o = new Calculator;
$this->assertEquals(0, $o->add(0, 0));
}
/**
* Generated from @assert (0, 1) == 1.
*/
public function testAdd2() {
$o = new Calculator;
$this->assertEquals(1, $o->add(0, 1));
}
/**
* Generated from @assert (1, 0) == 1.
*/
public function testAdd3() {
$o = new Calculator;
$this->assertEquals(1, $o->add(1, 0));
}
/**
* Generated from @assert (1, 1) == 2.
*/
public function testAdd4() {
$o = new Calculator;
$this->assertEquals(2, $o->add(1, 1));
}
}
?>
sb@wopr-mobile ~ % phpunit CalculatorTest PHPUnit 3.0.0 by Sebastian Bergmann. .... Time: 00:00 OK (4 tests)
24/09/2006 at 16:32 Permalink
Reply
25/09/2006 at 05:21 Permalink
Reply