dongliugu8843 2017-02-24 09:18
浏览 55
已采纳

这有可能编写好的测试,避免模拟和“期望”内部方法吗?

Is this possible to avoid mocking in phpunit?

My concept is to: - write unit tests to test smaller parts - when it comes to do a integration/functional test then it's possible to inject a null object class using the dependency injection (so it's good to have everything interfaced). But integration tests could be separated from unit tests.

The reason why I don't like the mocking is that I see that its underused in every test, it's totally not readable. I was thinking about separation on unit testing and integration testing.

Could this in most cases be alternative to mocking, or is the mocking not replaceable at all? What's the best practice?

  • 写回答

1条回答 默认 最新

  • duancong7573 2017-02-25 16:31
    关注

    Of course, you don't have to use mocks. You need fakes

    A Fake avoids overspecifying a test for a very invasive contract, like the order of calls and precise parameters; a real implementation is more robust to changes in the contract.

    This helps in focusing on the essence of your test (because you don't put long mocks' expectations in your tests). Also, it's possible to replace mocks at all.

    Consider the example in this article.

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

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制