Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

An Example of Test-Driven Development Expand / Collapse
Author
Message
Posted Thursday, April 30, 2009 12:25 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 1:15 PM
Points: 388, Visits: 1,044
Comments posted to this topic are about the item An Example of Test-Driven Development

Andy Leonard
CSO, Linchpin People
Follow me on Twitter: @AndyLeonard
Post #707432
Posted Thursday, April 30, 2009 1:37 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Tuesday, June 21, 2011 10:03 AM
Points: 577, Visits: 102
I like this a lot, it's a good demonstration of what it means to do test driven development. Everyone uses their own techniques, I tend to favor test harnesses that write to log tables/files. But this great; a good many projects fail because nobody can thoroughly test them.

Signature is NULL
Post #707453
Posted Thursday, April 30, 2009 2:17 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Monday, October 27, 2014 9:23 AM
Points: 3,241, Visits: 5,003
Nice well demonstrated article. Still alot of confusions in my mind that WHY to through this long procedure of creating project, adding query files (if talk about the example in the article) . On can manually create a simple script file to accomplish the task.

But, I would say that I might be too far away from the necessities of the TD3. Once again, Nice Article.



----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sometimes, winning is not an issue but trying.

You can check my BLOG here

Post #707474
Posted Thursday, April 30, 2009 2:25 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 4:39 AM
Points: 1,865, Visits: 593
I enjoyed this article; a good introduction to test-driven database development, something I have been looking to implement for quite some time.

I would be interested to see this expanded with some more practical examples, how you test complex stored procs, or triggers. Also, how do you deal with changing data from one environment to another?

Looking forward to more in this series.

Tom


Life: it twists and turns like a twisty turny thing
Post #707477
Posted Thursday, April 30, 2009 3:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, January 26, 2010 3:33 PM
Points: 14, Visits: 31
I completely agree with the fact of writing sql scripts for deployment including tests and using sqlcmd is a very good practice, I use to do it in a similar way.
But what is the relation with test driven development? TDD means that you model your application in order to pass the tests you define and refactor it iteratively, that's not the same than making unit tests on your scripts.
Post #707496
Posted Thursday, April 30, 2009 6:25 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 5:01 PM
Points: 10,295, Visits: 13,280
Loved the article. I really need to get more into Test-Driven Development.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #707617
Posted Thursday, April 30, 2009 7:23 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, December 12, 2013 1:09 PM
Points: 111, Visits: 541
Andy: Great article: Simple and effective. If people want to delve deeper, that's what the discussion forum is for!

Comparing notes:

Why consider the "test first" technique? 1. I find it helps me focus on one feature at a time, which in turn helps me break down the complexity of a project into many simple parts. So it helps me manage complexity. 2. It keeps testing from becoming a neglected afterthought. I can manage the risks in quality issues up front.

Why write reproducible tests? I feel more confident about making changes and adjustments if I can rerun the tests and get empirical evidence that things aren't broken. If I can efficiently make changes, I'm more agile.

I develop mostly in SQL Server 2000 right now as I'm sure others do, which doesn't have the try/catch feature. However, there are tools in 2000 for raising errors: RAISERROR ('User-defined Error in usp_ThisStoredProcedure.', 16, 1). custom code or a framework can offer reporting of test success and failure: EXEC tsu_failure @FailureMessage.

I've been using the TSQLUnit testing framework: http://tsqlunit.sourceforge.net/. TSQLUnit gives me the test suite logical grouping of tests with a setup and teardown for the group. Test code is written in stored procedures. The framework organizes the stored procedures through simple naming conventions. The framework gives some simple stored procedures to execute to run and manage the tests. Changes are rolled back at the conclusion of the tests.

I find that I use the unit tests mainly to set up and use test data (insert, update and delete test records) and test the functionality of stored procedures (did the stored procedure delete the test recordset as expected?).

I tend to not test all DDL (data definition language) statements such as whether or not certain objects exist except when necessary. For most of my DDL test needs, I've got the RedGate tool SQL Compare which compares every aspect of every object between my development and production. So, if the goal is to make sure nothing unexpected has changed, this tool does it for me in my environment where I don't require remote deployment.

As a developer, I feel more agile when I use test-driven development techniques and I think I produce better quality code. It can be done even in SQL Server 2000.


Bill Nicolich: www.SQLFave.com.
Daily tweet of what's new and interesting: AppendNow
Post #707668
Posted Thursday, April 30, 2009 8:46 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 1, 2010 6:18 PM
Points: 7, Visits: 28
I like the idea of Test Driven Development very much, but I'm not sure this is exactly how I would want it to go. Even in this simple example, the script that is created is actually an application to create the database. Instead I think I would be trying to keep it as lean as possible. Maybe do a check and print a result - and maybe fail. I can see where the script (application) created in the example could get to be bigger than the database project itself. If that permanently solved all the problems, that might work. But for continuous development, it means that new developers have to master not only the database, but the application. They would have to figure out how to modify the application to change the database.

Still, there is something here in "TD3", and the presentation of SS2005 features employed is interesting.
Post #707734
Posted Thursday, April 30, 2009 11:00 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, May 12, 2014 1:27 PM
Points: 1,386, Visits: 824
This strikes me as a great approach to use for high-quality, (almost) self-documenting code.

I think the overhead of time and effort, at least when one is first implementing this technique, seriously compromises it's usefulness. That is to say, i probably don't have the patience to use this approach when i can just write stuff off-the-cuff, and i know for a fact that my boss does not have the patience.

Thanks for the article, Andy. I just don't think i'll ever be able to really use it.
Post #707851
Posted Thursday, April 30, 2009 11:14 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 11:32 AM
Points: 266, Visits: 2,602
What a well-written article. I like how you explain things. Also, your writing style is easy to read and the touch of humor keeps me engaged.

Alas, like others, I'm not convinced of the usefulness of this kind of approach. I'm not a lazy developer. I don't mind extra work for good value. For example, I document extensively even though it is no fun and does not directly affect the product. I just don't see the benefit of doing test driven development -- especially for database development.

But, at least now I feel I really understand the approach and how to implement it. If one is sold on the concept of test driven development to begin with, your approach and set of scripts makes a lot of sense. I will definitely read any other articles you publish in the future on the subject. Who knows, maybe I'll be converted. Thanks.
Post #707860
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse