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

  • Comments posted to this topic are about the item Easy and Repeatable Testing of DB Code (Stored Procs, etc.) with DbFit

    SQL#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR

  • Looks interesting, if a little clunky in places. Not that testing is easy!

  • 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;

  • Nice one. Well presented...:)

  • 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...:w00t:) 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.

  • 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#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR

  • Anirban Paul (11/13/2008)


    Nice one. Well presented...:)

    Thanks, I appreciate it. 🙂

    Take care,

    Solomon.......

    SQL#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR

  • 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?

  • 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#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR

  • 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#https://SQLsharp.com/ ( SQLCLR library ofover 340 Functions and Procedures)
    Sql Quantum Lifthttps://SqlQuantumLift.com/ ( company )
    Sql Quantum Leaphttps://SqlQuantumLeap.com/ ( blog )
    Info sitesCollations     •     Module Signing     •     SQLCLR

  • Most of the Fit fixtures you can run from Fitnesse can also be run by FitRunner.exe from the command line. You can run a DoFixture, ActionFixture, ColumnFixture, RowFixture, etc. via FitRunner.exe. Is it possible to use FitRunner.exe to execute DbFit fixtures?

  • Is there any way to increase the command timeout in DBFit?

    I would like to test some complex data warehouse ETL stored procedures, but I've hit a problem as several run for longer than the default timeout (30 seconds), even on test data.

  • Solomon Rutzky (11/13/2008)


    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

    Solomon, in my experience the "SELECT * FROM Table1 to test that change" approach is very inefficient. Come to think of it, next month or next year you will have to add some more test data for some other requirement, and that will break your "test that change" piece. It is much better to test exactly the change - the difference between the original and the modified states.

  • Most of the Fit fixtures you can run from Fitnesse can also be run by FitRunner.exe from the command line. You can run a DoFixture, ActionFixture, ColumnFixture, RowFixture, etc. via FitRunner.exe. Is it possible to use FitRunner.exe to execute DbFit fixtures?

    in .NET, yes. FolderRunner and other .NET runners are 100% compatible with the normal fitnesse runner. In Java, the fit runner is not 100% compatible with fitnesse runners, so you can't do it from the command line.

  • Is there any way to increase the command timeout in DBFit?

    if you can do that in the connection string, then yes (just set it in the connect operation). Otherwise, not at the moment.

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic. Login to reply