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 关于#linux#的问题(输入输出错误):出现这个界面接着我重新装系统,又让修电脑的师傅帮我扫描硬盘(没有问题)用着用着又卡死(相关搜索:固态硬盘)
  • ¥15 cv::resize不同线程时间不同
  • ¥15 web课程,怎么做啊😭没好好听课 根本不知道怎么下手
  • ¥15 做一个关于单片机的比较难的代码,然后搞一个PPT进行解释
  • ¥15 python提取.csv文件中的链接会经常出现爬取失败
  • ¥15 数据结构中的数组地址问题
  • ¥15 maya的mel里,怎样先选择模型A,然后利用mel脚本自动选择有相同名字的模型B呢。
  • ¥15 Python题,根本不会啊
  • ¥15 会会信号与系统和python的来
  • ¥15 关于#python#的问题