Unit testing Database Access Layer Methods

    I thought of something that I wanted to make note of while I was testing an existing Database Access Layer method today.
    The unit test set-up and tear-down for tests of a database access method should only remove the records it creates rather than truncating or deleting all records from the affected table(s). Unit tests should leave resources in the same state that they were in before the test was run. Truncating or deleting all records assumes you have a clean database before and after your tests being run. Delete only the records created within the tests. If you have demo data in your database, it can then remain in the database without being affected by the tests being run.
    I know that this might not be feasible when you are just adding a test to an existing test suite, but it should be something to consider refactoring toward.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s