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

前端 未结 16 880
孤街浪徒
孤街浪徒 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 18:04

    But I get the impression you're actually more concerned with performance, which isn't really the preserve of unit testing at all. Unit tests are supposed to be fairly atomic and are intended to check behaviour rather than performance. And in that case you're almost certainly going to need production-class loads in order to check query plans.

    I think there are two quite distinct testing areas here: the performance, and the actual logic of the stored procedures.

    I gave the example of testing the db performance in the past and, thankfully, we have reached a point where the performance is good enough.

    I completely agree that the situation with all the business logic in the database is a bad one, but it's something that we've inherited from before most of our developers joined the company.

    However, we're now adopting the web services model for our new features, and we've been trying to avoid stored procedures as much as possible, keeping the logic in the C# code and firing SQLCommands at the database (although linq would now be the preferred method). There is still some use of the existing SPs which was why I was thinking about retrospectively unit testing them.

提交回复
热议问题