Web服务调用的Gherkin测试 [英] Gherkin tests for webservice calls

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

问题描述

我们正在使用Specflow自动化我们的回归套件,但是现在我们希望将其带入自动化Web服务的新水平.

We are using Specflow for automating our regression suite but now we would like to take it to a next level of automating our webservices.

使用小黄瓜"Gven-When-Then",我如何使用/编写Web服务调用.

Using the Gherkin "Gven-When-Then", how can I use / write the webservices calls.

例如:对于以下请求,我如何编写给定的-什么时候-然后?

For e.g : How do I write my given - when - then for the below request?

请求

    <soapenv:Header/>

    <soapenv:Body>

            <ns:GetConsolidatedBookingAccountHistory>

                    <ns:request>

                            <ns1:ServiceAuthenticationRequest>

                                    <ns1:Password>?</ns1:Password>

                                    <ns1:Station>?</ns1:Station>

                                    <ns1:UserName>?</ns1:UserName>

                            </ns1:ServiceAuthenticationRequest>

                            <ns2:BookingID>?</ns2:BookingID>

                            <ns2:CutOffDate>?</ns2:CutOffDate>

                    </ns:request>

            </ns:GetConsolidatedBookingAccountHistory>

    </soapenv:Body>

推荐答案

我要做的第一件事是停止将Specflow视为自动化工具,而不再是. Specflow是一种协作工具(尽管它确实有助于自动化). Specflow在那里,您团队中的每个人都可以了解系统将什么作为输入,什么动作将触发系统以及系统将什么作为输出返回.它有助于定义需求并提供清晰度.它还使任何人都可以了解测试失败时发生的情况.

The first thing I would do is stop thinking of Specflow as an automation tool, its not. What Specflow is is a collaboration tool (although it does help with automation). Specflow is there so everyone on your team understands what the system takes in as an input, what action triggers the system, and what the system returns as an output. It helps define requirements and provides clarity. It also allows anyone to understand whats happening when a test fails.

考虑到这一点,让我们看一个电子邮件登录的示例(带有用户名,密码和提交),我希望您考虑给定的输入时间,触发时间和输入输出,触发时间和输出. :

With that in mind lets look at the example of an email login (with a user name, password, and submit), and I would like you to think of given, when, and then as instead Input, Trigger, and Output:

输入就是您要提供给系统的内容,它要接受什么.在这种情况下,它将是我们的用户名和密码.我将其描述为:

Input is what you're providing to the system, what does it take in. in this case it would Our user name and password. And I would describe this as:

Given I have a valid username and password

现在这可以工作,但是在小黄瓜中,您应该避免在步骤的中间使用单词and,相反,我们可以这样做:

Now this could work however, in Gherkin you should avoid using the word and in the middle of a step, instead we could do this:

Given when I have a valid username
And I have a valid password

触发是发生的事情,采取了什么措施,采取了什么措施(这是BDD中的行为).理想情况下,这不应描述确切的操作(避免使用诸如单击,键入等之类的字词).而是描述一般行为.在我们的示例中,它可能类似于:

Trigger is what happens, what action is taken, what is the action taken (this is the behavior in BDD). Ideally this shouldn't describe exact action (avoid words like click, type, etc). Instead describe the general behavior. In our example this could look like:

When I login

同样,我只描述了行为,我没有说When I type in my username and password and hit submit我使它变得非常笼统

Again I only discribed the behavior, I didn't say When I type in my username and password and hit submit I made it very general

最后,我们有了输出,期望的结果是什么,应该发生什么.在我们的示例中,可能是:

Finally, we have our output, what is the result we are expecting, what should happen. In our example this may be:

Then I should be taken to my inbox

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

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