Hi there!
Today, I'll demonstrate how you can enhance the simplicity of your API testing using AI within 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.
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
open in terminal (or an equivalent) and run commands:
git clone https://github.com/PavelMal/PostmanTesting.git
cd PostmanTesting
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. 🙂)
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.
You’ve got your first set of tests including checking response time.
Try other prompts such as:
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.
Another valuable feature is response visualization. Let's explore it together. Type 'Visualize response as table' and see the magic
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.
Open a terminal.
Run the following command to install Git:
sudo apt update
sudo apt install git
Once the installation is complete, verify it by typing:
git --version
git --version
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install git
git --version
sudo apt update
sudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
Install Docker Compose:
Run the following commands to download the latest version of Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Verify the installation:
docker-compose --version
docker --version
docker-compose --version
docker --version
docker-compose --version