Has anyone had any success in unit testing SQL stored procedures?

前端 未结 16 914
孤街浪徒
孤街浪徒 2020-12-12 17:38

We’ve found that the unit tests we’ve written for our C#/C++ code have really paid off. But we still have thousands of lines of business logic in stored procedures, which o

16条回答
  •  被撕碎了的回忆
    2020-12-12 17:56

    I do poor man's unit testing. If I'm lazy, the test is just a couple of valid invocations with potentially problematic parameter values.

    /*
    
    --setup
    Declare @foo int Set @foo = (Select top 1 foo from mytable)
    
    --test
    execute wish_I_had_more_Tests @foo
    
    --look at rowcounts/look for errors
    If @@rowcount=1 Print 'Ok!' Else Print 'Nokay!'
    
    --Teardown
    Delete from mytable where foo = @foo
    */
    create procedure wish_I_had_more_Tests
    as
    select....
    

提交回复
热议问题