Trying to write up cucumber feature steps for REST API test.
I am not sure which approach is better:
Given I log in with username and password When I add one "tv" into my cart And I check my cart Then I should see the item "tv" is in my cart
or
Given the client authenticate with username and password When the client send POST to "/cart/add" with body "{item: body}" Then the response code should be "200" And the response body should expect "{success: true}" When the client send GET to "/cart" Then the response code should be "200" And the response body should expect "{"items": ["tv"]}"
Is there any convention to follow when people trying to write cucumber steps for REST API?
If you are not a big fan of command-line tools and rather like a GUI client to test your REST API then Postman is the best tool for you. It comes as a Chrome extension and you can install it on your chrome browser and from thereon. It is probably the most popular tool to test your REST API.
BDD (Behavior-Driven Development) is a way of developing code based on the expected behavior of the code as experienced by the users. When testing APIs for BDD tests, it's important to configure BDD correctly and to keep the count of BDDs to a minimum.
I just stumbled on this helpful article: https://www.gregbeech.com/2014/01/19/effective-api-testing-with-cucumber/
To summarize...
Scenario: List fruit Given the system knows about the following fruit: | name | color | | banana | yellow | | strawberry | red | When the client requests a list of fruit Then the response is a list containing 2 fruits And one fruit has the following attributes: | attribute | type | value | | name | String | banana | | color | String | yellow | And one fruit has the following attributes: | attribute | type | value | | name | String | strawberry | | color | String | red |
Validating a result against JSON is tricky business because if the result is an array, the elements may not be the same order as how you are validating in the test.
Edit: Updated link using finderAUT's comment. Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With