SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Easy and Repeatable Testing of DB Code (Stored Procs, etc.) with DbFit


Easy and Repeatable Testing of DB Code (Stored Procs, etc.) with DbFit

Author
Message
Solomon Rutzky
Solomon Rutzky
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3374 Visits: 3029
Comments posted to this topic are about the item Easy and Repeatable Testing of DB Code (Stored Procs, etc.) with DbFit

SQL# - http://www.SQLsharp.com/
Andy Warren
Andy Warren
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: Moderators
Points: 25663 Visits: 2746
Looks interesting, if a little clunky in places. Not that testing is easy!

Andy
SQLAndy - My Blog!
Connect with me on LinkedIn
Follow me on Twitter
Alexander Kuznetsov
Alexander Kuznetsov
Say Hey Kid
Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)

Group: General Forum Members
Points: 713 Visits: 824
How would you test the following cases:
- my stored procedure returns an unordered result set;
- my stored procedure returns two result sets;
- my stored procedure modifies two tables and returns a result set;
Anipaul
Anipaul
SSCrazy Eights
SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)SSCrazy Eights (9.8K reputation)

Group: General Forum Members
Points: 9833 Visits: 1407
Nice one. Well presented...Smile



Roger Fleig
Roger Fleig
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 346
I really like the idea of the community building a unit testing tool for db application code. I also like the wiki-style in principle -- it engenders collaboration and empowerment. A really strong plus is if the wiki format supports revision history, style guidelines and annotations like wikipedia. If it has true multi-database sql language support then that is a real plus too. Let's also cheer for open source -- thus allowing you to customize it in your own environment.

My job normally is not to test application code, like a stored procedure, but rather to test that concept of a stored procedure works. (I test SQL Server...:w00tSmile But I think some of the same lessons apply:

Developers will write great unit tests if they have a low overhead tool. IMHO, this means adopting something that runs in or near the IDE they already use. Visual Studio, NUnit and JUnit give you this. A wiki page will be very different and may be an inhibitor for that reason.

Code re-use looks hard here. I see some signs of a sort of "#include" or "import" but re-using wiki-stlye syntax seems a little hard to me. Also it duplicates the functionality of existing programming languages and environments. Without proper code-reuse you end up with copy/paste code and lack of abstractions where you really need them. Developers may do the same thing 5 different ways. This hurts you when you want to make disruptive changes.

Similar to the last point, a very common operation on test code is to make updates to introduce a new dimension, variable or behavior. I would have some concerns about using a wiki for making such updates. Your bulk search/replace options are very limited since all of your code is locked up in wiki pages. Others might have a better feel for these options than I in this case.

Most importantly, though, I don't see a very rich way to programmatically calculate results. I like to use a "oracle" or a "model" that I trust. Worst case you can persist the results (like this solution does.) But saving your "expected results" can be problematic because of type system differences, subtle changes, "over verificaiton" -- checking more than you intended to -- and most importantly human error! One or two rows may work, but if your functionality needs to be tested at 1000 or 1,000,000 rows this is very impractical. You would then need to do tricks to capture your results and just verify rowcount or an aggregate-- a missing abstraction in this tool.

Like I said, this is a cool idea, and maybe for very limited unit testing it is great. But I would worry about betting too much on such a system and building a large body of unit tests that need to be maintained.
Solomon Rutzky
Solomon Rutzky
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3374 Visits: 3029
Alexander Kuznetsov (11/13/2008)
How would you test the following cases:
- my stored procedure returns an unordered result set;
- my stored procedure returns two result sets;
- my stored procedure modifies two tables and returns a result set;


Hello Alexander.

1) for an UNordered result set, use the regular "Query" operation. This can be seen in most of the examples. Take a look at the http://localhost:8085/DemoSuite.AdHocQueries page. The test will only check for Ordered results if you use the "Ordered Query" operation.

2) Two or more result sets does not work. Only the first result set returned will be shown and tested.

3) To test any result set, use either the "Query" or "Ordered Query" operations. It does not matter what else the Stored Procedure does.

Take care,
Solomon...

SQL# - http://www.SQLsharp.com/
Solomon Rutzky
Solomon Rutzky
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3374 Visits: 3029
Anirban Paul (11/13/2008)
Nice one. Well presented...Smile


Thanks, I appreciate it. Smile

Take care,
Solomon.......

SQL# - http://www.SQLsharp.com/
Alexander Kuznetsov
Alexander Kuznetsov
Say Hey Kid
Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)Say Hey Kid (713 reputation)

Group: General Forum Members
Points: 713 Visits: 824
Solomon Rutzky (11/13/2008)
Alexander Kuznetsov (11/13/2008)
How would you test the following cases:
- my stored procedure modifies two tables and returns a result set;



3) To test any result set, use either the "Query" or "Ordered Query" operations. It does not matter what else the Stored Procedure does.

Take care,
Solomon...


IMO yes it does - how do you verify that the modifications are exactly as you expect?
Solomon Rutzky
Solomon Rutzky
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3374 Visits: 3029
Roger Fleig (11/13/2008)
A really strong plus is if the wiki format supports revision history, style guidelines and annotations like wikipedia. If it has true multi-database sql language support then that is a real plus too. Let's also cheer for open source -- thus allowing you to customize it in your own environment.


Hello Roger. Yes, FitNesse (the main testing framework that DbFit runs in), is a simple wiki that supports versioning and basic markup. It is not nearly as extensive as the MediaWiki software that WikiPedia runs on, but the end goal here is not publishing articles. Yes, DbFit does support more databases than just SQL Server. It supports Oracle and MySQL and someday soon will support PostgreSQL.


Developers will write great unit tests if they have a low overhead tool. IMHO, this means adopting something that runs in or near the IDE they already use. Visual Studio, NUnit and JUnit give you this. A wiki page will be very different and may be an inhibitor for that reason.


I do agree that sticking within the SSMS IDE would be ideal, but I (and we here at ChannelAdvisor) have found the separation between SSMS and DbFit to not be a hindrance. We have instances of DbFit running on our local machines and we have centralized FitNesse servers that combine both the application level integration tests and the DbFit tests.


Code re-use looks hard here. I see some signs of a sort of "#include" or "import" but re-using wiki-stlye syntax seems a little hard to me. Also it duplicates the functionality of existing programming languages and environments. Without proper code-reuse you end up with copy/paste code and lack of abstractions where you really need them. Developers may do the same thing 5 different ways. This hurts you when you want to make disruptive changes.


I am not sure that this is as difficult or as much of an issue that you seem to feel it is. The include functionality allows for whatever common set up you need. Outside of that, the idea is to test low level pieces so I am not sure how much code reuse, no matter how easy or hard, would be a part of this type of testing. These tests can be very isolated and is not the same situation as when building an application and needing consistency in the business layer.


Similar to the last point, a very common operation on test code is to make updates to introduce a new dimension, variable or behavior. I would have some concerns about using a wiki for making such updates. Your bulk search/replace options are very limited since all of your code is locked up in wiki pages. Others might have a better feel for these options than I in this case.


I am not sure I see this as an issue. Any number of tests can be performed per page and any number page pages can exist. Making slight changes would be easy if the structure of testing them was planned ahead of time.


Most importantly, though, I don't see a very rich way to programmatically calculate results. I like to use a "oracle" or a "model" that I trust. Worst case you can persist the results (like this solution does.) But saving your "expected results" can be problematic because of type system differences, subtle changes, "over verificaiton" -- checking more than you intended to -- and most importantly human error! One or two rows may work, but if your functionality needs to be tested at 1000 or 1,000,000 rows this is very impractical. You would then need to do tricks to capture your results and just verify rowcount or an aggregate-- a missing abstraction in this tool.


In this situation I think the idea is to create a controlled environment of test data to begin with. If you control the inputs and then have a result set that you expect to get, then you don't need to do extra calculations because if each individual row is correct, then together they are all correct. Also, I would not test that size of data in this tool. The idea here is for functionality and not performance. Hence I would test a number of rows that would show the variety of data coming back but on a smaller scale. Testing performance of 1 million rows or something like that can be handled through a different testing mechanism. The idea here is to make sure that the logic is correct, and that does not require production level volumes of data.

Like I said, this is a cool idea, and maybe for very limited unit testing it is great. But I would worry about betting too much on such a system and building a large body of unit tests that need to be maintained.


I appreciate your comments but would argue that DbFit addresses specifically the issue of maintenance. That is one reason I like it so much. It encapsulates all of the functional testing without having to put that testing structure into the DB. And as your system grows these tests can be combined into Suites and easily changed to adapt to changes in the logic. Since it is a wiki it is really easy to comment and document what the test is trying to accomplish so that someone coming in much later to update it can spend less time trying to figure out what it is trying to do.


Take care,
Solomon....

SQL# - http://www.SQLsharp.com/
Solomon Rutzky
Solomon Rutzky
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3374 Visits: 3029
Alexander Kuznetsov (11/13/2008)
Solomon Rutzky (11/13/2008)
Alexander Kuznetsov (11/13/2008)
How would you test the following cases:
- my stored procedure modifies two tables and returns a result set;


3) To test any result set, use either the "Query" or "Ordered Query" operations. It does not matter what else the Stored Procedure does.


IMO yes it does - how do you verify that the modifications are exactly as you expect?



Ok, sorry, I misunderstood the intent of that question. To test both the modifications made in the Stored Procedure and the result set returned, you would do the following all within the same page:

a) use the "Query" operation calling EXEC on the Stored Procedure to test the result set
b) use the "Query" operation again calling SELECT * FROM Table1 to test that change
c) use the "Query" operation again calling SELECT * FROM Table2 to test that change

If you look at the http://localhost:8085/DemoSuite.ExecuteAndExecuteProcedure example, this scenario is shown by the first test on that page which inserts into a table via a Stored Procudure and captures its result set:

EXEC DBFitTest_Insert 'Mark Robinson', ' Orange ', 0

and then the third test does:

SELECT * FROM DBFitTest WHERE TestID = @bridget


Hope this helps. Take care, Solomon......

SQL# - http://www.SQLsharp.com/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search