Link to home
Start Free TrialLog in
Avatar of craftedsoftware
craftedsoftware

asked on

Override class method in unit test to return expected results

In a unit test, I would like to be able to change the default behaviour of a method for a class instance in order to validate that my class handles the edge case properly.

For example,

In my test case when I make a call as follows

System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection ();

For this particular test case I want it to always return an Exception with particular details.

This way I can always ensure that the code for database connection failures work.

Any thoughts on how I might solve this problem.

ASKER CERTIFIED SOLUTION
Avatar of Jesse Houwing
Jesse Houwing
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial