質問

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 ?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top