Prakash
Prakash

Reputation: 103

Simulating exceptions using shim or stub

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

Answers (1)

TGH
TGH

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

Related Questions