Q:

Deleting test rows with an auto increment key in a unit test

Is there any ways to delete the rows inserted by a test case in an unit test? 
Usually if the key is an auto-increment one I have to store the ID of the rows where the test case inserted so I can delete them during the tearing down phase.
However, sometimes the test case crashes or throws an unexpected error where the tea down phase does not occur (In my case it's PHP's fatal exception error). I am having problem removing those newly created rows in such cases.
I have considered assign a chunk of IDs for testing, say 1 to 100; but as the code inserting the rows is using an auto incrementing key, I cannot force the code to use the IDs reserved for testing.
Is there any way I can 'tag' a row as 'testing' so I may easily clean them up outside of a test case in case it crashes?
I am using PHP, SimpleTest and MySQL

A:

The common practice is to use a special blank database just for tests. Then in setUp() you fill your tables with test data, and in tearDown() you clean everything.
To be more precise: declare some cleanDatabase() method and invoke it in 2 places, in setup and in teardown.

