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

后端 未结 1 1488
半阙折子戏
半阙折子戏 2021-02-02 15:21

We\'re required to use the API of an external partner. The API is in a good shape and we got access to a sandbox environment we can use for automatic testing.

We already

相关标签:
1条回答
  • 2021-02-02 16:08

    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.

    0 讨论(0)
提交回复
热议问题