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 123»»»

Easy and Repeatable Testing of DB Code (Stored Procs, etc.) with DbFit Expand / Collapse
Author
Message
Posted Tuesday, November 04, 2008 4:56 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, April 17, 2014 3:01 PM
Points: 342, Visits: 1,781
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/
Post #596989
Posted Thursday, November 13, 2008 6:36 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: Moderators
Last Login: 2 days ago @ 9:01 AM
Points: 6,705, Visits: 1,680
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
Post #602041
Posted Thursday, November 13, 2008 8:40 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, January 06, 2014 6:58 PM
Points: 219, Visits: 823
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;



Post #602186
Posted Thursday, November 13, 2008 9:42 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, March 20, 2014 7:32 AM
Points: 5,191, Visits: 1,368
Nice one. Well presented...:)


Post #602237
Posted Thursday, November 13, 2008 12:05 PM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, October 02, 2009 5:41 AM
Points: 2, 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...) 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.

Post #602309
Posted Thursday, November 13, 2008 1:02 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, April 17, 2014 3:01 PM
Points: 342, Visits: 1,781
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/
Post #602340
Posted Thursday, November 13, 2008 1:04 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, April 17, 2014 3:01 PM
Points: 342, Visits: 1,781
Anirban Paul (11/13/2008)
Nice one. Well presented...:)


Thanks, I appreciate it. :)

Take care,
Solomon.......





SQL# - http://www.SQLsharp.com/
Post #602342
Posted Thursday, November 13, 2008 1:23 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, January 06, 2014 6:58 PM
Points: 219, Visits: 823
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?
Post #602364
Posted Thursday, November 13, 2008 3:28 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, April 17, 2014 3:01 PM
Points: 342, Visits: 1,781
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/
Post #602437
Posted Thursday, November 13, 2008 3:46 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, April 17, 2014 3:01 PM
Points: 342, Visits: 1,781
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/
Post #602442
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse