Database as SUT API?
A common technique for setting up test fixtures is Back Door Setup (see Back Door Manipulation on page X) and for verifying test outcomes, Back Door Verification (see Back Door Manipulation). But when is a test that is interacting directly with the database behind a system under test (SUT) not considered to be going through the "back door"?
On a recent project, some friends were struggling with this very question although at first, they didn't realize it. One of their analysts who was also a power user seemed overly focused on the database schema. At first, they put this down to a Powerbuilder background and tried to break him of the habit. That didn't work. The analyst just dug in his heels. They tried explaining that on agile projects it was important not to try to define the whole data schema at the beginning of the project and that this required them to evolve the schema as the requirements were implemented.
Of course, the analyst complained every time they modified the database schema as it broke all his queries. As the project unfolded, they slowly started to understand that the analyst really did need a stable database against which to run queries. It was his way to get at the data generated by the system.
Once they understood this, they were able to treat this query schema as a formal interface provided by the system. Customer tests were written against this interface and developers had to ensure that those tests still passed whenever they changed the database. To minimize the impact of database refactorings, they defined a set of query views that implemented this interface. This allowed them to refactor the database as needed.
When might you find yourself in this situation? Any time your customer uses reporting tools (such as Crystal Reports) against your database, there is an argument to be made as to whether part of the requirements is a stable reporting interface. Similarly, if the customer uses scripts (such as DTS or SQL) to load data into the database, the argument can be made that there is a requirement for a stable data loading interface.
Copyright © 2003-2008 Gerard Meszaros all rights reserved