WCF 单元测试 [英] WCF Unit Test

查看:35
本文介绍了WCF 单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对 WCF 服务进行单元测试?有任何可用的第 3 方工具吗?

How to unit test WCF services? Any 3rd Party tools available?

推荐答案

正如 aku 所说,如果您正在测试服务方法(即代码行为),那么您可以直接对其进行单元测试并绕过 WCF 基础结构.当然,如果您的代码依赖于 WCF 上下文类(如 OperationContext),那么我建议引入包装器,就像 ASP.NET MVC 为 HttpContext 所做的那样.

As aku says, if you're testing service methods (ie code behaviour) then you can unit test that directly and bypass the WCF infrastructure. Of course, if your code depends on WCF context classes (like OperationContext) then I suggest introducing wrappers much like ASP.NET MVC does for HttpContext.

对于测试连接性,这取决于您配置的端点类型.在某些情况下,您可以在单元测试中自行托管 WCF 服务(就像使用 WCF Windows 服务一样)并进行测试.

For testing connectivity, it will depend on the type of endpoints you have configured. In some cases you can just self-host your WCF service inside the unit test (like you would with a WCF Windows Service) and test that.

但是,如果您想测试特定于那些托管环境的 WCF 行为(即 SSL、身份验证方法),您可能需要启动 ASP.NET 开发 Web 服务器甚至 IIS.这会变得很棘手,并且会开始对每个人的开发机器和构建服务器的配置提出要求,但这是可行的.

However, you may need to spin up the ASP.NET Development Web Server or even IIS if you want to test WCF behaviour specific to those hosting environments (ie SSL, authentication methods). This gets tricky and can start making demands on the configuration of everyone's development machine and the build servers but is doable.

这篇关于WCF 单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆