Integration testing: Mock external API vs. use external API sandbox

我的未来我决定 提交于 2019-12-03 06:22:42

I believe there should be 2 level of verifications we need to do when we interface with an external API:

  • API verification: verify that the API works according to its specs and/or our understanding
  • App functionality verification: verify that our business logic works according to the expectation to the API that passes API verification

In our case, we use a mock API together with real and mock API verification.

  • Mock API allows us to isolate any runtime errors/exceptions to app functionality only, so we don't blame any external party for issues
  • The same API verification is executed against both real and mock APIs, to make sure that the real one works the way we expect, as well as the mock one should mimic the real one correctly

If along the way, external API changes, API verification may turn red, triggering changes in mock API. Changes in mock API may make app verification turn red, triggering changes in app implementation. This way you never miss any gap between external API and app implementation (ideally).

Another extra benefit of having a mock API + API verification is that your developers can use it as a documentation/specification of how the API is supposed to work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!