Fixture Reuse in PHPUnit 3.4

Sebastian Bergmann » 25 February 2009 » in New Features » 1 Comment

As mentioned earlier, PHPUnit 3.4 adds support for Test Dependencies as introduced by Kuhn et. al. in JExample: Exploiting Dependencies Between Tests to Improve Defect Localization.

Today I implemented fixture reuse based on test dependency information:

<?php
class StackTest extends PHPUnit_Framework_TestCase
{
    public function testPush()
    {
        $stack = array();
        $this->assertEquals(0, count($stack));
 
        array_push($stack, 'foo');
        $this->assertEquals('foo', $stack[count($stack)-1]);
        $this->assertEquals(1, count($stack));
 
        return $stack;
    }
 
    /**
     * @depends testPush
     */
    public function testPop(array $stack)
    {
        $this->assertEquals('foo', array_pop($stack));
        $this->assertEquals(0, count($stack));
    }
}
?>

Just like JExample, PHPUnit 3.4 introduces producer-consumer relationships to unit-testing.

  • A producer is a test method that yields its unit under test as return value.
  • A consumer is a test method that depends on one or more producers and their return values.

PHPUnit 3.4 skips any test method whose producer has failed and the return value of a producer is injected into its consumers.

Defined tags for this entry: , , ,

Trackback specific URI for this entry

1 Comment to "Fixture Reuse in PHPUnit 3.4"

Display comments as (Linear | Threaded)
  1. Giorgio Sironi
    25/02/2009 at 18:07 Permalink
    - Not sure if it is correct from an architecture point of view - but very nice for an integration test (create/read/update/delete a comment, an article...) implementation.

    Reply

1 Trackback to "Fixture Reuse in PHPUnit 3.4"

  1. Sebastian Bergmann 18/08/2009 at 12:39
    The first release candidate of PHPUnit 3.4 is now available. Among the many new features introduced in this new version, the most notable are the support for test dependencies and fixture reuse as well as the possibility to run tests in separate PHP pr

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Submitted comments will be subject to moderation before being displayed.