Step 2: Test what you have developed
This may sound all too obvious to mention?
Trust me, it is NOT!
I can say so, because I have found myself guilty of having released code into production several times that has not been carefully tested as it could have been.
Why? Maybe because I missed a test case since I am kind of my own first-line tester? Maybe I thought: Nah, this is only a small change. No need for a full-blown test script?
Even if you like to think of you as a good developer, even the smartest developer does make mistakes and these mistakes will come back to bite you one day sooner or later. Testing code is not for the weak and timid as the Klingons would probably put it.
How do you test your code? Well, first thing has to be that the code provides the expected result. If the code is a stored procedure with parameters, the resultset has to be tested for any possible and reasonable combination of these parameters. Some of my procedures do have a very long list of input parameters and with a handful of combination of these parameters most of the daily business can be done, while some more exotic combinations occur very infrequently. So, building up your own test suite over time with test cases is essential. For example, after being a couple of month in production, one user executed a stored procedure for the first time with a very exotic combination of input parameters and the procedure gave an incorrect resultset back. Nobody notices this bug before because it was “hidden” in some OUTER JOIN condition and was only valid for this combination. Now I have added this sample calls I captured from this user in our user acceptance environment and added them to my test suite for this part of the database along with the expected “correct” resultset. Everytime now I make some changes to this procedure, I just have to open my test script, execute the captured all there and compare the resultsets (I use Excel for that, because it is quite convenient for this task).
Testing does not necessarily have to be full-blown regression testing, but as soon as your database objects are a bit more complex than “SELECT * FROM table”, at least basic testing should take place.
But are we now done with testing? No way!
Once the code is functionally working, it’s time to look at how the code performs. Is it running fast? Is it affecting other bits of code?
One of the things I really like about a declarative language like SQL is, that you can express things in many almost natural language ways and still get the same result. But it is always worth testing out how different formulations of a statement are carried out by SQL Server. They are often not equally evaluated by the database engine. Sometimes you will be really suprised how different the resulting execution plans are. When you have identified the formulation giving you the “best” execution plan, pick that and go for it.
What I tend to do when I have more than one formulation giving almost identical performance, I save all variations down in a test script and keep that script for future review. Additionally I assign myself another tracker in our tracking application to review this bit of code in several weeks time after that code is released.
Now that you have tested the code you have developed is it ready to make it into the production environment? Not quite! Usually you would want to test it under production-like conditions. We have a testing environment which is almost identical to the production environment, including data and server specs. So, whenever we are done with our testings, we push the changes to the testing environment and then ask our testers to “play around” with the changes. We prefer to have “business power users” as testers. Simply because they are familiar with the numbers they work with each day and can tell you almost always right away if the results are plausible. When they are plausible, they dig deeper into the changes and verify a sample of the result for correctness. Otherwise the changes must be corrected in the development environment and the testing phase begins anew.
Once these testers are happy with the changes, it’s time to prepare the actual release to push the changes into the production environment. With business buy-in to the RAD/Agile approach they become partners in the development and testing cycle. This includes acknowledgement and acceptance of the formal testing/sign-off/release trade-offs between RAD/Agile vs. more formal methods.
Step 3: Change Management Meetings
Do the DBA’s need to review code before it goes into production?