What's the best way to write unit tests for a

2019-04-23 14:55发布

When writing unit tests for an API wrapper, should I be making real calls to the REST API endpoints or should I use mocl responses that simulate successful and erroneous calls?

1条回答
倾城 Initia
2楼-- · 2019-04-23 15:49

Unit tests mean testing only your unit (API wrapper), nothing else. Thus, unfortunately, you should mock the entire API.

On the other hand this never really gives me enough confidence, so I go for system tests (also known as component tests). In that case you should run your API wrapper against existing API, maybe embedded and started along with your test. In integration test, the ultimate scenario, you run your API wrapper against real, but most likely test instance of the API (sandbox, dev environment).

In well established area of database testing: unit tests mock entire DAO level, component tests run against in-memory database while integration tests connect to real database with some fake data.

查看更多
登录 后发表回答