Hi...

Originally Posted by
kyberfabrikken
Actually, it doesn't solve everything. There are some UI toolkits which break it
.
As for the original question, I do all these types of testing.
1) Web tests as acceptance tests. That is, before the code is written we grab a spec into a bunch of test cases. This is often done with the stakeholder. E.g....
PHP Code:
function testCanAddNoteToAccount() {
$this->nowJuly(1, 2008);
$account = $this->accounts()->createAccount(
'george', 'secret', 'George', 'Peppard',
'george@ateam.com', 'The A-Team', '11 Apollo Studios',
'AS1 23K', 'GB', '020 7485 8855', '020 7424 8844');
$this->get($this->home() . "admin/accounts/?account=$account");
$this->setField('note', 'Something fishy about this account');
$this->setField('nickname', 'me');
$this->click('Add note');
$this->assertText('01/07/2008 by me Something fishy about this account');
}
2) We use mock objects to test the controllers. E.g...
PHP Code:
function testIfAccountDoesNotExistThenRedirectToCreateAccount() {
$request = new Request(array('account' => 100));
$continuation = new MockContinuation();
$continuation->expectOnce('redirectTo',
array('*', array('error' => 'Account 100 does not exist')));
new AccountSummary(
$request, new MockSession(), $continuation,
new MockAlert(), new MockAccounts());
}
3) Undelying model classes are unit and integration tested. E.g...
PHP Code:
function testNotesFetchedNewestFirst() {
$this->nowJuly(1, 2008);
$account = $this->accounts()->createAccount(
'fred', 'secret', 'Fred', 'Bloggs', 'fred@bloggs.com',
'Bloggsworth', '1 Blogg st.', 'BL1', 'GB', 123, 456);
$this->accounts()->addNote($account, 'Something important', 'Me');
$this->nowJuly(2, 2008);
$this->accounts()->addNote($account, 'Something more important', 'Her');
$this->assertEqual($this->accounts()->getNotes($account), array(
array('note' => 'Something more important', 'account' => $account,
'nickname' => 'Her', 'written' => '2008-07-02 12:00:00'),
array('note' => 'Something important', 'account' => $account,
'nickname' => 'Me', 'written' => '2008-07-01 12:00:00')));
}
4) We use web tests as integration. E.g...
PHP Code:
function testNicknameRememberedAcrossSessions() {
$this->nowJuly(1, 2008);
$account = $this->accounts()->createAccount(
'george', 'secret', 'George', 'Peppard',
'george@ateam.com', 'The A-Team', '11 Apollo Studios',
'AS1 23K', 'GB', '020 7485 8855', '020 7424 8844');
$this->get($this->home() . "admin/accounts/?account=$account");
$this->setField('note', 'Something fishy about this account');
$this->setField('nickname', 'me');
$this->click('Add note');
$this->restart();
$this->get($this->home() . "admin/accounts/?account=$account");
$this->assertField('nickname', 'me');
}
All the code snippets are from what I am working on right now, warts'n'all.
yours, Marcus
Bookmarks