What are standard/best practices for creating unit tests for functionality using databases?

后端 未结 3 1088
慢半拍i
慢半拍i 2021-02-02 14:34

I get the idea behind unit testing however am trying to think of a clean simple way do it when it requires database functionality. For instance I have a function that return re

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 15:29

    Personally, I create a dummy testing database and populate it with a known data set for each testing run (I do that right in the setUp functions). Then the tests run against that data set, and then it's removed on tearDown...

    Now, this is more of a Integration test than an Unit test (And personally I treat it differently from a unit test, run on its own schedule along with other integration tests), but it's still quite useful.

提交回复
热议问题