At the moment, I'm writing a test that will cause a WCF service to throw an exception on purpose. I've 开发者_StackOverflow社区prevented the debugger from stopping to the particular exception and trying to run the test in debug mode all the way up to the point where the caller receives the exception (instead of a normal result).
But is there a more efficent way to implement a test for exceptions? (Or more specifically, exceptions that the service does not handle internally but throws a FaultException instead)? At this point I'm stuck between manually disabling each exception from Visual Studio settings or just running the test without debugging.
Test environment in this case is Windows 7 with Visual Studio 2010.
The simplest solution is to host the WCF service in IIS and point our client to that.
Once you figure out what exceptions actually get thrown and when, mock the service contract with something like Moq, and your unit tests can test against that instead of the real service.
精彩评论