Testing DB insert?
Posted: Mon Sep 04, 2006 3:57 pm
I should probably read more about how AUT's work, but I can't help but ask:
When testing a SQL function, say:
I would include the nessecary model classes, etc inside my unit test...I would pass several amounts of data to create_user() possibly by doing something like:
The way I see it, I have two options for calling these functions:
1) I setup a test DB
2) I use the production DB, but...
Thus in my test I would be killing two birds with one stone...
However I'm getting the impression from what I've read that I would ideally keep tests atomic...
So the better method is to use a test database, testing create methods on their own...
And in the delete test's I would just have to create a temporary user and then delete???
Which way is the suggested norm???
Cheers
When testing a SQL function, say:
Code: Select all
create_user($fname, $lname, $age, $sex, $addres = '')Code: Select all
create_user('Ted', 'Bindy', 23, 'M', '123 Test Street');
create_user('Ted', 'Bundy', 23, 'M', '123 Test Street');
create_user('Ted', 'Binder', 23, 'M', '123 Test Street');
create_user('Ted', 'Bunter', 23, 'M', '123 Test Street');1) I setup a test DB
2) I use the production DB, but...
Code: Select all
$r1 = create_user('Ted', 'Bindy', 23, 'M', '123 Test Street');
$r2 = create_user('Ted', 'Bundy', 23, 'M', '123 Test Street');
$r3 = create_user('Ted', 'Binder', 23, 'M', '123 Test Street');
$r4 = create_user('Ted', 'Bunter', 23, 'M', '123 Test Street');
delete_user($r1);
delete_user($r2);
delete_user($r3);
delete_user($r4);However I'm getting the impression from what I've read that I would ideally keep tests atomic...
So the better method is to use a test database, testing create methods on their own...
And in the delete test's I would just have to create a temporary user and then delete???
Which way is the suggested norm???
Cheers