TDD with SQL and data manipulation functions

Posted by Xophmeister on Programmers See other posts from Programmers or by Xophmeister
Published on 2012-08-25T12:55:03Z Indexed on 2012/09/14 21:48 UTC
Read the original article Hit count: 240

Filed under:
|
|
|

While I'm a professional programmer, I've never been formally trained in software engineering. As I'm frequently visiting here and SO, I've noticed a trend for writing unit tests whenever possible and, as my software gets more complex and sophisticated, I see automated testing as a good idea in aiding debugging.

However, most of my work involves writing complex SQL and then processing the output in some way. How would you write a test to ensure your SQL was returning the correct data, for example? Then, say if the data wasn't under your control (e.g., that of a 3rd party system), how can you efficiently test your processing routines without having to hand write reams of dummy data?

The best solution I can think of is making views of the data that, together, cover most cases. I can then join those views with my SQL to see if it's returning the correct records and manually process the views to see if my functions, etc. are doing what they're supposed to. Still, it seems excessive and flakey; particularly finding data to test against...

© Programmers or respective owner

Related posts about database

Related posts about sql