Why not hit the database inside unit tests?

后端 未结 7 1831
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 09:16

I\'ve read in blogs that the database should not be hit when the unit tests run. I understand the theory, however say i have complex store procedures that are part of a busi

7条回答
  •  臣服心动
    2021-01-04 09:37

    There are two main reasons for unit tests not hiting the database:

    • You want your tests to go as fast as possible
    • You want to test your code as a single unit, not how it integrates with other code/ database.

    In your case you need to test the stored procedures. Then you need to write a test that runs those stored procedures. Either you can run them via your code (Integration test) or you can run them directly from the test (sort of a unit test). In both cases you can use Nunit.

提交回复
热议问题