How to write Unit Tests for functions that rely on dynamic data?

后端 未结 6 2137
萌比男神i
萌比男神i 2021-02-06 01:30

Lets say you have a website, that uses a function to retrieve data from the database and returns the result to be displayed/parsed/etc...

Since the data that is retrieve

6条回答
  •  太阳男子
    2021-02-06 01:55

    Ignoring the fact that you are talking about the DB I think you may be looking for your unit tests to cover every eventuallity where as that can lead to set of diminishing returns. If I were you I'd cover a standard path and then a couple of edge cases. The fact is you cannot pragmatically test everything.

    Here's some further reading

    http://37signals.com/svn/posts/3159-testing-like-the-tsa
    How deep are your unit tests?
    http://johnnosnose.blogspot.co.uk/2012/04/re-over-testing.html
    http://martinfowler.com/bliki/TestCoverage.html

    Looking at your specifc db related problem, to test this function you probably need to create a seam to pre poulate the data so you can cover those cases.

提交回复
热议问题