Functional and Regression testing of the application by a developer, will always enhance the quality of the code and also ensuring that the existing features are not broken.
As a developer working on the RESTFUL services, the application extensively used to test REST API endpoints is Postman.
Postman is a standalone software testing API (Application Programming Interface) platform to build, test, design, modify, and document APIs.
Well-documented Postman collection will always help any developer to use the application APIs in various environments on the go. Other than documenting the APIs in postman it can also be used extensively like designing the test cases and validating the feature or flow of the application on a single run.
On the Postman application, click the
newoption and select the
Once the collection is created, we will be able to add various scripts, environment variables to be used to the collection.
Pre-Request Scripts: This option allows you to run the script before making the request. For instance, you can set the environment variables before making the request.
Variables: This option allows the addition of the environmental values to be used in the collection.
New folder can be created inside the parent collection for each flow, which includes all the requests needed to complete the particular flow. For instance, Create student flow can have requests like
create student endpointand
get student endpoint.
Both the requests inside the collection will have the required test cases written inside the test tab.
This test should have all the test cases designed by the developer which is expected for an endpoint to be returned, which ensures the endpoints are working as expected.
Newman is a command-line collection runner for Postman. It allows you to effortlessly run and test a Postman collection directly from the command line.
Once the postman collection is created with all the flows needed for the application, a developer can leverage `Newman's tool to run the postman collection and validate the test cases.
Newman provides out of box reporting formats which include `cli, json, HTML, JUnit.
Newman can also be integrated into the CI/CD pipelines to automate the validation of the application.
nodeJs has to be installed in your system based on your distribution.
Run the following command to install the npm package of newman globally.
npm install -g newman
Source code for the sample spring application with CRUD operations and postman collection with the test cases can be found in the following link:
Postman Runner and Testing Github
Run and Test the application:
- Clone the above git repo and run the java application on your preferred IDE.
- Import the collection to the postman and run the collection using a runner.
- To run in CLI, use the following command inside the postman directory through the terminal.
newman run file.json
- To run the test and display/store the result, use the following command.
newman run file.json -r cli
Postman Runner Collection
Postman Newman integration
Top comments (0)