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 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100