How are integration tests written for interacting with external API?

后端 未结 4 1212
慢半拍i
慢半拍i 2020-12-04 07:41

First up, where my knowledge is at:

Unit Tests are those which test a small piece of code (single methods, mostly).

Integration Tests ar

4条回答
  •  -上瘾入骨i
    2020-12-04 07:52

    This is more an additional answer to the one already given:

    Looking through your code, the class GoogleAPIRequest has a hard-encoded dependency of class Request. This prevents you from testing it independently from the request class, so you can't mock the request.

    You need to make the request injectable, so you can change it to a mock while testing. That done, no real API HTTP requests are send, the live data is not changed and you can test much quicker.

提交回复
热议问题