Test Refactoring
Posted: Sun Oct 25, 2009 3:49 pm
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
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'
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());
}