|
From: Marcus B. <ma...@la...> - 2009-07-30 09:09:58
|
Hi...
troels knak-nielsen wrote:
> I wonder what aspect of test cases makes them particularly suitable
> for multiple inheritance?
I think it's the fixture reuse without spoiling the spec. We do lot of
this...
class MyTest extends WebBaseCaseToHoldFixtures {
// ...messy setup() and tearDown() chaining.
function testCanChangeAddress() {
$this->accounting()->createAccount('fred');
$this->authentication()->login('fred', 'secret');
$this->navigation()->goToHome();
$this->click('MyAccount');
$this->setField('address', '1 Here street');
$this->click('Update');
$this->accounting()->assertAddress('fred', '1 here street');
}
...
}
class WebBaseCaseToHoldFixtures extends WebTestCase { ... }
I'd rather do this...
class MyTest extends WebTestCase {
function __construct() {
$this->given(new AccountExists('fred'));
$this->given(new LoggedInAs('fred', 'secret'));
$this->given(new StartFromHomePage());
}
function testCanChangeAddress() {
$this->click('MyAccount');
$this->setField('address', '1 Here street');
$this->click('Update');
$this->assertAddress('fred', '1 here street');
}
...
}
I haven't made the difference all that stark, but basically:
1) Fixtures would have a standardised format and become a kind of plug-in.
2) setUp() and tearDown() would be pulled directly from the composed
classes leaving the setUp() and tearDown() free. Also stops the error
where you forget to chain these.
3) __call() is used to inline supplied assertions.
What do you think?
>
> --
> troels
yours, Marcus
|