Hi guys,

I've read a lot about TDD but have never thorougly stuck to it. I think that the biggest problem to me is the set up of the project. The architecture.

Assume you want to build a site that features a ToDo list. You have the graphical part and the back-end part (PHP that pulls the data and returns as XML/JSON). The unit tests in my eyes would be like this (the object to be tested is ToDoList)
Code:
class TestToDoList{
    function test_create_single_todo_without_timestamp_assert_failure(){...}
    function test_create_single_todo_without_description_assert_failure(){...}
    function test_create_single_todo_without_permission_assert_failure(){...}
    function test_create_single_todo_assert_success(){...}
.....
}
Now in this case it is really easy as there is a very clear line on where you can write the PHPUnits.

Now my problem with TDD here would be testing the actual creation of the ToDo item?

The tested class would obviously have a method create_single_todo(...); which would add an entry to the DB. Assume further that this method would not return an identifier for the todo it just created (or that it creates another hidden bit of data somewhere that is related to the todo and whose existence also needs to be verified for the test to be successful).

I guess that there are a few answers to the issue:

a) prior to running every single testcase you wipe the db of all entries and then check the integrity after the database was updated with create_single_todo(), or use a separate database for the tests?

b) You change the signature of create_single_todo so that it returns a flag (true/false) (i.e. the method itself checks if everything went smoothly)

c)You only check if the todo was added (assuming that if the todo entry was added so were the others)?


Now that I've typed all of this I think I'd go with A though making sure that for each test case I use a blank database.

How do you feel about this?


Laurent