Writing unit tests for a REST-ful API

前端 未结 2 1857
故里飘歌
故里飘歌 2021-02-04 12:42

I\'m planning on writing unit tests for a REST-ful API and I\'m wondering about the approach I should take.

The aspect that concerns me the most is related to the datab

2条回答
  •  情书的邮戳
    2021-02-04 13:06

    Usually, in unit tests, you try to remove all dependencies beyond the unit (usually a function/class/object) that you are testing. The classic way to accomplish this in your case (for databases) is through the use of mocks. http://en.wikipedia.org/wiki/Mock_object

    Basically, you implement a "FakeDatabase" that shares the API of the actual database that returns known values.

提交回复
热议问题