Testing methods that make http requests

前端 未结 7 1357
悲哀的现实
悲哀的现实 2021-02-09 01:31

I have some methods in my app that make http requests. Is there a good way to simulate network failures and bad responses for the unit tests?

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-09 02:24

    For network failures nothing beats first unplugging your computers ethernet cable (or d/c it's wireless) and then unplugging whatever cable gives you access to the cloud.

    If by bad responses you mean HTTP errors you can write ASP scripts that will always throw specific errors. If you want to test malformed HTTP packets you'll have to write a simple socket app to do that.

提交回复
热议问题