使用 Cucumber 和 Rspec 通过 BDD 开发 SOAP 客户端
作为学习经验,我正在开发一个小型 Rails 应用程序,该应用程序应该查询现有的 SOAP API/Web 服务(使用 Handsoap gem),并将简单地将在那里收集的信息呈现给用户。
我喜欢使用 rspec,并且正在习惯使用 Cucumber 来测试我的应用程序。 让我困惑的部分是如何测试与 API 的交互,即来回传递 XML 请求和响应的“非表示”部分。
非常感谢任何提示和指示!
谢谢!
As a learning experience I'm developing a small Rails application that is supposed to query an existing SOAP API/web service (using the handsoap gem) and will simply present the information gathered there to a user.
I like using rspec and am getting used to cucumber for testing my applications. The part that has me stumped is how to test the interaction with the API, i.e. the 'non-presentation' part of passing back and forth XML requests and responses.
Any tips and pointers are very much appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看 fakeweb gem。
它有助于破坏网络互操作性,
即您可以创建测试响应:
并禁用发送 http 请求的功能:
Take a look at fakeweb gem.
It helps to stub network interoperability,
i.e. you can create test responses:
and disable ability to send http requests:
我假设您正在谈论功能/集成样式测试而不是单元测试,在这种情况下,我可能会考虑模拟 Web 服务的接口并在较低级别上对代码进行单元测试。
但回到黄瓜。 正如 Aslak Hellesøy 在 Stack Overflow q 810410 中指出的那样,没有什么可以阻止您做这个。 当您编写了实际要测试的行为的场景后,您只需在步骤定义中实例化正确的对象并调用适当的方法即可。 如果您需要的话,也可能将其与返回值或内容的一些断言结合起来。 请参阅 Rspec 期望了解如何加载 rspec 的
should()用黄瓜。
I'm assuming you're talking about functional/integration style tests and not unit tests in which case I would probably consider mocking the interface for the web service and unit testing the code on a lower level.
But to return to cucumber. As Aslak Hellesøy points out in Stack overflow q 810410 there is nothing that should prevent you from doing this. When you have written the scenarios for what behaviour you are actually going to test you just have to instantiate the right objects in the step definitions and call the appropriate methods. Possibly also combining it with a few asserts on return values or content if that is what you need. See Rspec expectations for how to load rspec's
should()
with cucumber.使用最新版本的 Handsoap,您可以使用模拟 http 驱动程序,在 http 级别进行模拟。 请参阅:
Http::HttpMock
以及tests/ 中的示例account_test.rb
With the newest version of Handsoap, you can use a mock http-driver, to mock out at the http-level. See:
Http::HttpMock
and the example intests/account_test.rb