Gherkin tests for webservice calls

只愿长相守 提交于 2019-12-12 02:37:34

问题


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.

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?

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>


回答1:


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

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

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

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


来源:https://stackoverflow.com/questions/34442589/gherkin-tests-for-webservice-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!