C# 测试 WCF 服务的最佳方法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/620333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 10:34:17  来源:igfitidea点击:

What's the best way to test WCF services?

c#.netwcf

提问by Nick

I've used this tool that microsoft ships with visual studio because it's quick and dirty

我使用了微软随 Visual Studio 提供的这个工具,因为它又快又脏

http://msdn.microsoft.com/en-us/library/bb552364.aspx

http://msdn.microsoft.com/en-us/library/bb552364.aspx

But it's kinda clunky and hard to work with. Are there any other useful test clients out there that you use and don't require creating a new visual studio project and compiling code?

但它有点笨重且难以使用。是否有其他有用的测试客户端可供您使用并且不需要创建新的 Visual Studio 项目和编译代码?

EDIT: I'm looking more for a graphical test tool that I can use to do quick ad-hoc tests of systems in our different environments without having to write a bunch different tests.

编辑:我正在寻找更多的图形测试工具,我可以用它在我们不同的环境中对系统进行快速的临时测试,而不必编写一堆不同的测试。

回答by Darin Dimitrov

SoapUIis another web service testing tool. I strongly recommend it.

SoapUI是另一个 Web 服务测试工具。我强烈推荐它。

回答by John Saunders

You're not going to find any better tool for creating automated tests of WCF servcies than to use your favorite unit test framework and write tests. The test client, nor soapUI will create a test that can run in a Continuous Integration scenario.

您不会找到比使用您最喜欢的单元测试框架和编写测试更好的工具来创建 WCF 服务的自动化测试。测试客户端和soapUI 都不会创建可以在持续集成场景中运行的测试。

回答by blowdart

Well I end up writing unit tests in MS test. Before each test the service is hosted by the test assembly, and ripped down afterwards. Sure it's not unit testing, so purists will shudder, but it does mean I can run tests as often as I like.

好吧,我最终在 MS 测试中编写单元测试。在每次测试之前,服务由测试程序集托管,然后被拆除。当然这不是单元测试,所以纯粹主义者会不寒而栗,但这确实意味着我可以随心所欲地运行测试。

回答by Dror Helper

If you need to test the client logic: You can use mocking/Isolation framework to stub the actual calls to the server and use a unit testing framework to write proper Unit Tests.

如果您需要测试客户端逻辑:您可以使用模拟/隔离框架来存根对服务器的实际调用,并使用单元测试框架编写适当的单元测试。

Testing the server logic can be even easier - all you need is to test the call to the business logic and stub calls to external components (i.e. database).

测试服务器逻辑甚至更容易——您只需要测试对业务逻辑的调用和对外部组件(即数据库)的存根调用。

There is no actual benefit of unit testing the full interaction between the client to the server because you know that WCF works instead add integration testing of the entire environment on a dedicated server/clients.

对客户端与服务器之间的完整交互进行单元测试并没有实际好处,因为您知道 WCF 的工作方式是在专用服务器/客户端上添加整个环境的集成测试。

回答by Dror Helper

I didn't mean to imply that soapUI does not work for a WCF service exposed using basicHttpBinding. Using basicHttpBinding would work because the service would be functioning as a legaxy ASMX web service. However, if one is to switch the binding (or use multiple bindings) to netTcpBinding for example, i dont think it would still be possible to invoke the methods of that service using soapUI. The scenario I'm describing is quite common wherein you have a WCF service exposed on the web using basicHttpBinding endpoint for maximum interoperability, and another endpoint as netTcpBinding(for max performance) used only internally.

我并不是要暗示soapUI 不适用于使用basicHttpBinding 公开的WCF 服务。使用 basicHttpBinding 会起作用,因为该服务将作为传统的 ASMX Web 服务运行。但是,例如,如果要将绑定(或使用多个绑定)切换到 netTcpBinding,我认为仍然无法使用soapUI 调用该服务的方法。我所描述的场景很常见,其中您使用 basicHttpBinding 端点在 Web 上公开了一个 WCF 服务以实现最大互操作性,另一个端点作为 netTcpBinding(以获得最大性能)仅在内部使用。

回答by Clangon

There is this new test client called SOA Cleaner, I recommend you try it. It supports WCF. can be found at: http://xyrow.com.

有一个名为 SOA Cleaner 的新测试客户端,我建议您尝试一下。它支持 WCF。可以在:http: //xyrow.com找到。

回答by Mikhael

I ran WcfStorm with it's 15 day eval and I'm impressed with it. Connect to the service and all methods are exposed. Click a method and you can build multiple test cases. After you are done you can save these tests (gonna keep mine as a solution file with the service) and as you make changes you can run all tests which satisfies continuous testing. It also has a command line which should allow you to integrate into your build machine for true continuous testing.

我用它的 15 天评估运行了 WcfStorm,我对它印象深刻。连接到服务并公开所有方法。单击一个方法,您可以构建多个测试用例。完成后,您可以保存这些测试(将我的测试作为服务的解决方案文件保留),并且在进行更改时,您可以运行所有满足连续测试要求的测试。它还有一个命令行,可以让您集成到构建机器中以进行真正的连续测试。

It also supports IronPython so you may be able to script removal of records your test added if you are good with that scripting language.

它还支持 IronPython,因此如果您擅长该脚本语言,则可以编写脚本删除测试添加的记录。

回答by Jordi

Amazing WCFStorm, but I think is too expensive for an independent developer.

很棒的 WCFStorm,但我认为对于独立开发人员来说太贵了。

As Darin said, I also recommend soapUI.

正如达林所说,我也推荐soapUI。

But there's a special case, that soapUI doesn't suuport JSON request when you use REST in WCF and send the request as a POST message.

但是有一种特殊情况,当您在 WCF 中使用 REST 并将请求作为 POST 消息发送时,soapUI 不支持 JSON 请求。

In that case, you can use a tool I found here:

在这种情况下,您可以使用我在此处找到的工具:

WCF RESTful JSON automated testing

WCF RESTful JSON 自动化测试

回答by Kirsten Pasha

WCFStormis useful to test the way you're describing.

WCFStorm可用于测试您描述的方式。