I want to unit test a MVP presenter class . but its interaction to the service is not through interface ( it uses a concrete class ) . now I wonder is there anyway to mock service class without being have to change the structure ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The usual way of mocking in C#/VB.NET is by overriding virtual methods with the implementation you require for a particular scenario. For that reason, an interface is the approach most commonly used as all its methods are abstract.
Is there a reason why you are reluctant to change the service dependency to an interface? An alternative is making the methods you want to test virtual, so you can override them in your mocks, but I would not recommend that, as it is a bit dirty.
The whole point of unit testing is just testing a particular unit, so having a dependency to an implementation instead of an interface really beats the point.