Web服务通信的自动化测试

发布于 2024-07-05 05:01:22 字数 763 浏览 4 评论 0 原文

我有一个将消息发送到外部 Web 服务的应用程序。 我使用 MSBuild 构建并部署此应用程序Cruisecontrol.NET。 当 CCNET 构建和部署应用程序时,它还使用 NUnit 运行一组测试。 我现在也想测试网络服务通信。

我的想法是,作为构建过程的一部分,应该生成 Web 服务(基于外部 Web 服务 WSDL)并将其部署到构建服务器本地 Web 服务器。 Web 服务应该做的就是接收消息并将其放置在文件系统上,这样我就可以使用普通的 NUnit 等来检查它。 这也将使开发变得更加容易,因为新开发人员只需运行构建脚本并启动并运行(不必花时间建立与第三方服务的连接)。

是否存在可以轻松模拟基于 WSDL 的 Web 服务的现有实用程序? 有人使用 MSBuild 做过类似的事情吗?

是否有其他方法来测试此场景?

I have an application that sends messages to an external web service. I build and deploy this application using MSBuild and Cruisecontrol.NET. As CCNET build and deploys the app it also runs a set of test using NUnit. I'd now like to test the web service communication as well.

My idea is that as part of the build process a web service should be generated (based on the external web services WSDL) and deployed to the build servers local web server. All the web service should do is to receive the message and place it on the file system so I then can check it using ordinary NUnit for example. This would also make development easier as new developers would only have to run the build script and be up and running (not have to spend time to set up a connection to the third party service).

Are there any existing utilities out there that easily mock a web service based on a WSDL? Anyone done something similar using MSBuild?

Are there other ways of testing this scenario?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

年少掌心 2024-07-12 05:01:22

看看 NMock2。 它是一个开源模拟产品,允许您为支持丰富而深入的交互的界面创建“虚拟”实现。

例如,如果您的 WS 接口名为 IService 并具有 Data GetData() 方法,则您可以创建一个模拟,要求调用该方法一次并返回一个新的Data 对象:

var testService = mockery.NewMock<IService>();
Expect
    .Once
    .On(testService)
    .Method("GetService")
    .WithNoArguments()
    .Will(
        Return.Value(new Data());

测试结束时,调用 mockery.VerifyAllExpectationsHaveBeenMet() 以确保实际调用了 GetData 方法。

PS:不要将“NMock2”项目与“NMock RC2”混淆,后者在sourceforge 上也称为“nmock2”。 NMock2-该项目似乎已经取代了 NMock。

Take a look at NMock2. It's a open-source mocking product and allows you to create "virtual" implementations for interfaces that support rich and deep interaction.

For example, if your WS interface is called IService and has a Data GetData() method, you can create a mock that requires the method to be called once and returns a new Data object:

var testService = mockery.NewMock<IService>();
Expect
    .Once
    .On(testService)
    .Method("GetService")
    .WithNoArguments()
    .Will(
        Return.Value(new Data());

At the end of the test, call mockery.VerifyAllExpectationsHaveBeenMet() to assure that the GetData method was actually called.

P.S.: don't confuse the "NMock2" project with the "NMock RC2", which is also called "nmock2" on sourceforge. NMock2-the-project seems to have superseded NMock.

蓝眸 2024-07-12 05:01:22

这也可能是 - MockingBird。 看起来很有用。

This might also be something - MockingBird. Look useful.

南冥有猫 2024-07-12 05:01:22

在我的工作场所,我们使用 TypemocknUnit 用于我们的单元测试。

At my work place we are using Typemock and nUnit for our unit testing.

莳間冲淡了誓言ζ 2024-07-12 05:01:22

我刚刚开始研究 http://www.soapui.org/ ,看起来它会很好地工作用于测试网络服务。

另外,也许考虑在 Web 服务中添加一个抽象层,每个服务调用都会直接调用可测试的方法(在 Web 范围之外)? 我刚刚在我正在进行的一个更大的项目中做到了这一点,并且它的可测试性运行良好。

I just started looking into http://www.soapui.org/ and it seems like it will work nicely for testing web services.

Also, maybe look at adding an abstraction layer in your web service, each service call would directly call a testable method (outside of the web scope)? I just did this with a bigger project I'm working on, and it's testability is working nicely.

计㈡愣 2024-07-12 05:01:22

一般来说,测试此类事情的一个非常好的方法是使用模拟对象

在工作中,我们使用产品 TypeMock 来测试 Web 服务通信和其他外部依赖项等内容。 它需要花钱,因此它可能不适合您的需求,但我认为这是一个很棒的产品。 我可以从个人经验告诉你,它与 NUnit 和 CCNet 集成得很好。

它有一个非常简单的语法,你基本上可以说“当调用这个方法/属性时,我希望你返回这个值”。 它非常适合测试网络故障、文件不存在,当然还有 Web 服务等。

In general, a very good way to test things like this is to use mock objects.

At work, we use the product TypeMock to test things like Web Service communication and other outside dependencies. It costs money, so for that reason it may not be suitable for your needs, but I think it's a fantastic product. I can tell you from personal experience that it integrates very well with NUnit and CCNet.

It's got a really simple syntax where you basically say "when this method/property is called, I want you to return this value instead." It's great for testing things like network failures, files not being present, and of course, web services.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文