Reputation: 17
I have written a unit test with mocking the dependencies of the controller after that I have the real implementation of these dependencies, so should I replace the mock with the concrete implementation?
Upvotes: 0
Views: 293
Reputation: 233347
It's not clear what your question is, but it sounds as though you've written a test of a Controller using Test Doubles, and now you'd also like to test the actual dependencies that the Controller is going to have in production.
If so, there's at least two options open to you:
There's value in both, and disadvantages as well. J.B. Rainsberger creditably explains the problem with integration tests, and I don't think you should put all of your eggs in that basket. The test pyramid offers good guidance: Write most of your tests as unit tests, fewer as integration tests, and so on.
Thus, I suggest first testing the real implementations of the Controller's dependencies in isolation; i.e. not involving the Controller at all. Once you know that the dependencies work in isolation, a few integration tests may be in order, so that you demonstrate that they integrate well.
You should leave the test(s) you already wrote alone. Tests are most trustworthy if you edit them as little as possible.
Upvotes: 1