问题
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