doutuan8887 2016-09-23 16:15
浏览 19
已采纳

如何在没有外部通信的情况下将PHPUnit测试保持在内部?

Is it possible to ensure that no tests communicate with an external source? While I think all of my tests take care of mocking out any external dependencies, I'd like to know if there is any sort of catch all to ensure my test suite does not have any unintended communication with third party APIs et cetera.

  • 写回答

1条回答 默认 最新

  • douxie4583 2016-09-23 17:55
    关注

    Since this is tagged as Laravel, I'm going to assume that you'd prefer an answer based on Laravel.

    Assuming that you're not testing communication with an external API (which is worth doing at some point), you're going to want to approach it in the same way that you approach anything else.

    Mocking.

    Both your models and your API library are communicating with a data source. To test your models you mock them, so that you aren't interacting with the database. You need to do the same for your API, mock the class that returns the result, or skip it entirely and throw in an example response.

    It all depends entirely on what you are testing. If you don't wish to test how you handle data from the API, simply don't call anything that interacts with the API.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵