The easiest way to write your first test is using the tool we named Magic. To put it simply, with Magic you can make an API call and then it will automatically create a test based on the payload.
First of all, you need to make an API call with the console. For this example we are using our own test API:
Type in the URL and then press the Send button.
Next, tap the magic wand icon at the top right corner of the Console to launch the Magic tool.
The following screen will allow you to choose whether you want to create the input set (based on the data provided in the request) or skip it. Press Continue.
The next screen, allows you to choose if you want to create the assertions. You do, so press Continue once again.
At the end you will see a report about the applied changes.
Here is the result: a fully working draft of an API payload test.
Now, you can launch the test and see the report….
Tests are meant to validate an endpoint, so it makes a lot of sense to add more input sets and have the unit run against them.
Magic is able to understand basic things based on a single request and response. Refining it is mostly about transforming vague assertions to be more specific.
For example, we know that payload.content.options.mainColor can be a finite number of values. Therefore, using an “assert exist” assertion is a bit poor…
So let’s change it to an “assert in” that verifies the field value to be either “red” or “black_plain.”
Done! Your first test is ready to be scheduled now.