Reputation: 103
How do you simulate exception scenarios in unit test case?
We have a function which calls a service and we handled an exception when the service goes down or there's some sort of issues at the service end.
Now I want to know how to simulate the service-down or service-access-denied in unit test case using shim or stub.
Upvotes: 1
Views: 862
Reputation: 39278
I recommend using a mocking framework to simulate exceptions in the code under test. There are several to choose from, but MOQ is a very popular one.
Here's an example of how it can be done:
http://www.syntaxsuccess.com/viewarticle/mock-exceptions-using-moq
Upvotes: 1