开发者

do model need to be test separatly even if they are test using controller

I have writen a model to add user. then I writen a controller which call that method in model to add user.

After that I have writen phpunit test to fully test that controller. Because I am calling model in the controller to add user 开发者_如何学Pythonwhich is also testing the model.

My question is, do I need to create a separate test for model as well? Even that is being called in controller and I m testing the controller fully?


Ideally, when writing unit tests each unit of code (typically a class) is tested in isolation. This means having one test case that thoroughly tests your model class and another test case that tests your controller. If the model is fairly complex or takes a long time to access, you can substitute a mock object or stub in the controller test.

With Test Driven Development, you would only write code once you had a failing test. If you started with tests for the controller, I suppose you could end up testing the model. By tracking code coverage you could gain confidence that you had tested all of the model code.

However, without tests for the model alone, I would be worried that problems could arise during refactoring that wouldn't be caught by the controller test. It would also make it harder to diagnose a failure in a controller test: is the controller or the model at fault?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜