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

后端 未结 6 2281
萌比男神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 02:02

    I would build the data in the test itself. That way you can even test complicated scenarios for the ever changing data. The key point is that you can control the data changes in your tests by having a dedicated test db,

    Step 1: Insert the data you need into a db that is only used by the test Step 2: The db is now in a stable predictable state, so you can run your queries and test the output

提交回复
热议问题