visit
Streamline Your API Tests: Less is More
TL;DR: Use primitive steps to verify API behavior instead of direct requests.
Making a POST and immediately making a GET to check the existence of the resource with the payload is a straightforward solution.
Also, if your GET operation breaks, you will have many tests failing not relating to the test GET operation.
Instead of verifying resource creation through a GET and inspecting the JSON response, you can focus on primitive steps.
Check if the POST succeeded by validating the status code or checking the resource's existence.
Feature: Movie Management
Scenario: Create a movie and verify
When I send a POST request to "/movies" with the following data:
| title | director | year |
| Klendathu | Christopher Nolan | 2010 |
When I send a GET request to "/movies/Klendathu"
Then the response status should be 200
And the response should contain:
| title | director | year |
| Klendathu | Christopher Nolan | 2010 |
Feature: Movie Management
Scenario: Create a movie and verify
When I create a movie with the following details:
| title | director | year |
| Klendathu | Christopher Nolan | 2010 |
Then the movie "Klendathu" should exist in the system
## This is a low level existance postcondition
## Without relying on a GET request
You can detect this smell when you see test steps that use a GET request to verify the success of a POST.
You could train an AI to identify patterns of consecutive POST and GET requests in scenarios and suggest consolidating them into more abstract, primitive steps.
Remember: AI Assistants make lots of mistakes
Without Proper Instructions | With Specific Instructions |
---|---|
Focus your acceptance tests on the direct results of operations like POST.
//gzht888.com/how-to-find-the-stinky-parts-of-your-code-part-xi-sit35t1
Code Smells are my opinion.
As a rule, software systems do not work well until they have been used, and have failed repeatedly, in real applications.
Dave Parnas