Hi there!

Today, I'll demonstrate how you can enhance the simplicity of your API testing using AI within Postman.

What is Postman?

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.

Setting up the environment.

To begin, we require some endpoints for testing purposes. To fulfill this requirement, I've set up a dedicated server. If you're unfamiliar with Docker and Git, there's no need to worry—I've prepared comprehensive instructions on how to install them (Docker/docker-compose and git installation guidelines can be found towards the end of the article). Once you have Git and Docker in place, you can proceed next:

Ensure port 8080 is unoccupied; the application is operational on this port.

You need to clone a repo:

  1. open in terminal (or an equivalent) and run commands:

    1. git clone https://github.com/PavelMal/PostmanTesting.git
    2. cd PostmanTesting
    3. docker-compose up

Please wait for approximately 1-2 minutes, and after this time, you should observe a log entry resembling the following:


Starting qa-server ... done

Attaching to qa-server

qa-server    | 2023-08-10 05:19:17.741  INFO 1 --- [main] com.test.Application: Started Application in 5.183 seconds (JVM running for 6.1


This indicates that the application is now operational. To verify its proper functionality, simply initiate a request to:

http://localhost:8080/api/check


Expect a response status code of 200 OK.

Your progress is commendable. We have now successfully configured the testing environment.

This application offers the capability to generate and retrieve orders (an order being an object comprising three attributes: id, name, and price). Don't hesitate to utilize Swagger for this purpose: http://localhost:8080/swagger-ui.html#/ (It's not in vain that I added it to the project. 🙂)

Generate the initial order and tests to verify this functionality

Let’s move on to the most interesting part - open the Postman and create your first order


Well done! At this point, we can begin creating tests for that specific endpoint. However, before we proceed, consider this: we have an AI assistant at our disposal. Let's experiment with its capabilities.

  1. Click on ‘Tests’ tab
  2. Click on AI assistant button
  3. Write ‘Add tests to this request’ and submit it

You’ve got your first set of tests including checking response time.

Try other prompts such as:

Validation of error message

Let's proceed to create tests for the validation of error messages. In Postman, input a price of 0 and initiate a request. This action should result in a response code of 400 along with the following message:

"message": "Price can't be less than or equal to 0".

Leverage the AI assistant to compose a script:

response message should be "message": "Price can't be less or equal than 0"

You now possess two tests designed to check the 400 status code and verify the error message.

Great job!

I've included the logic to check the name/price/ID body parameters. Your task is to identify all possible scenarios and harness AI assistance to generate the corresponding tests.

Visualize response

Another valuable feature is response visualization. Let's explore it together. Type 'Visualize response as table' and see the magic

Postman collections

Last but not least, do not underestimate the value of utilizing collections, as this will enable your tests to maintain a structured framework. By employing collections, you can effortlessly oversee API requests alongside sets of tests.

I appreciate your attention! You are now prepared to harness AI for your API testing needs (Furthermore, you have acquired the fundamentals of Docker and Git).

Would greatly appreciate it if you could star my project.

Installation instructions for git

Ubuntu:

Open a terminal.

macOS:

Windows:

Installation instruction for docker/docker-compose

Ubuntu:

sudo apt update

sudo apt install -y docker.io

sudo systemctl start docker

sudo systemctl enable docker

macOS:

Windows: