Test Refactoring

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Test Refactoring

Post by josh »

Ok so I have most of my tests down to simple 1 line assertions. A lot of my tests just set up an 'expected', and an 'actual' object for instance, assign them to unit test as an object property, and each test method calls some verification like

Code: Select all

 
function testSubject()
    {
         $this->assertEquals( $this->expected->getSubject(), $this->actual->getSubject() );
    }
    
    function testBody()
    {
        $this->assertEquals( $this->expected->getBody(), $this->actual->getBody() );
    }
    
    function testSender()
    {
        $this->assertSameModel( $this->expected->getSender(), $this->actual->getSender());
    }
I noticed PHPunit implements 'data providers' (http://www.phpunit.de/manual/3.3/en/wri ... -providers), although I would be using a slightly different context, do you think it would be a good idea to use this verify domain logic to cut down on this type of repetitive test calls? I could see it helping me share logic between different tests more effectively, but it could also contradict with 'tests as documentation'
Post Reply