Writing Your First Test

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:
https://mastiff.apifortress.com/app/api/examples/retail/product?id=511

1

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.

1b

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.

2

The next screen, allows you to choose if you want to create the assertions. You do, so press Continue once again.

3

At the end you will see a report about the applied changes.

4

Here is the result: a fully working draft of an API payload test.

5

Now, you can launch the test and see the report….

6

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.

 

7

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…

8

So let’s change it to an “assert in” that verifies the field value to be either “red” or “black_plain.”

9

Done! Your first test is ready to be scheduled now.