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 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler