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

Write tsqlt tests for stored procedures. Expand / Collapse
Author
Message
Posted Wednesday, April 9, 2014 12:17 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 5:38 PM
Points: 31,368, Visits: 15,834
Looking for a number of articles here. Basically for each I'd like to see some type of code that you actually use at work. Nothing contrived, though obviously you might change table/column names.

Show the code, explain how you might test this in a few ways (Expected functions/happy path, edge cases, bad input) and then show how a few tests are written.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1560130
Posted Monday, May 5, 2014 8:55 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, September 27, 2014 7:07 AM
Points: 8, Visits: 98
Any interest in an article on using CodeSmith to generate tsqlt tests and avoid the need to write boiler plate code.

When testing stored procedures that return from one to N results sets. Or inline table valued functions that return a table. These types of tests will, typically, contain a fair amount of boiler plate. Fake some tables, insert some test data, execute the stored procedure, check the number of rows returned and in some cases the values or the range of those rows.

A couple other examples,
When writing tests for the CRUD style stored procedures, was an insert done, was an update done, does the table contain the updated values.

Tests that check the individual table schemas have not changed. Are the columns originally marked as not null still marked as not null today. Is a column that was created as nchar(60) still nchar(60) or did some one change the size of the column?

Anyway, I use CodeSmith to generate the boiler plate in these types of tests. Yes, I know that goes against the concepts of TDD, it does reduce the grunt work. I would show some snippets of the actual templates used but not go into a lot of detail on the template code.
Post #1567550
Posted Monday, May 5, 2014 10:19 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 5:38 PM
Points: 31,368, Visits: 15,834
TDD is head, or haven't you heard :) - http://david.heinemeierhansson.com/2014/tdd-is-dead-long-live-testing.html

This would be interesting. Maybe you can show Codesmith with a couple examples? If there are more patterns you use, then maybe a second article? I'm trying to teach people how to write tests and jumpstart their knowledge rather than having them stumble a bit.







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1567603
Posted Thursday, August 28, 2014 11:13 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 5:38 PM
Points: 31,368, Visits: 15,834
bump






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1608351
Posted Thursday, August 28, 2014 2:40 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:27 AM
Points: 35,769, Visits: 32,437
Steve Jones - SSC Editor (8/28/2014)
bump


Would you be interested in a more detailed explaination of why and how the test scripts for the "Tally OH" or the "Running Total" articles where developed?


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1608416
Posted Thursday, August 28, 2014 2:55 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 5:38 PM
Points: 31,368, Visits: 15,834
yes, separate pieces. Some thoughts on why/how you built them and what they accomplish in your mind would be great. Nice to have a setup for testing. I am thinking of a Stairway to testing at some point.






Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1608420
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse