开发者

Testing exception handling in a WCF service

开发者 https://www.devze.com 2023-03-28 22:08 出处:网络
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 tr

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消