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.

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

报告相同问题?