newman-reporter-integration
v1.1.1
Published
Json reporter based on Suits and tests for Integration testing
Downloads
757
Maintainers
Readme
Newman Integration Reporter
A integration reporter for Newman that formats and outputs test execution results grouped by suites, allowing for better insights into your Postman collection runs.
Table of Contents
Installation
You can install the integration reporter globally using npm:
npm install -g newman-reporter-integration
Usage
To use the integration reporter with Newman, run your collection with the following command:
newman run <path_to_collection> -r integration --reporter-integration-outputPath=\"<path_to_output_file>\"
Options
<path_to_collection>
: Path to your Postman collection file (e.g.,.json
).-r integration
: Specify the integration reporter.--reporter-integration-outputPath
: Specify the output path for the report file (e.g.,../results/report.json
).
Events
This reporter listens for several Newman events. Here are the main ones:
- request: Triggered after a request is completed, where you can access the request and response data.
- done: Triggered when the run is finished, providing final results and summary.
Example
Here is a complete example of how to run a Postman collection using Newman with the integration reporter:
newman run /path/to/your/collection.json -r integration --reporter-integration-outputPath=\"../results/report.json\"
This command will execute the collection located at /path/to/your/collection.json
and output the formatted results to ../results/report.json
.
Integration Reporter Code Structure
The integration reporter code should be structured as follows:
function integrationNewmanReporter(emitter, options, collectionRunOptions) {
// Your reporter implementation goes here.
}
module.exports = integrationNewmanReporter;
Make sure to handle different Newman events appropriately to gather and format the results you need.
Use Case
This integration reporter is particularly useful in CI/CD pipelines where you want to monitor the health of your APIs during integration tests. By grouping results by suites, it becomes easier to identify failing tests, which can be attributed to specific API endpoints or functionalities.
Example Scenario
Imagine you have a Postman collection that includes various suites like Health, Status, and User Management. Each suite contains requests to check the health of your services and verify status codes. When you run your collection, the integration reporter will:
- Group the results by suite.
- Provide clear visibility into which suite and requests are failing.
- Output a JSON file that can be used for further analysis or reporting in your CI/CD system.
JSON Example
{
"run": {
"collection": {
"name": "Example PR Tests",
"id": "your-collection-id",
"info": {
"description": "Collection for Example API tests"
}
},
"executions": [
{
"suite": "Health",
"requests": [
{
"name": "Get Token",
"status": "passed",
"statusCode": 200,
"responseTime": 120,
"response": {
"body": {
"token": "your_token_here"
}
},
"error": null
},
{
"name": "Health Check",
"status": "failed",
"statusCode": 500,
"responseTime": 150,
"response": null,
"error": "Internal Server Error"
}
]
},
{
"suite": "Status",
"requests": [
{
"name": "Check Service Status",
"status": "passed",
"statusCode": 200,
"responseTime": 80,
"response": {
"body": {
"status": "OK"
}
},
"error": null
},
{
"name": "Check Queue Status",
"status": "passed",
"statusCode": 200,
"responseTime": 95,
"response": {
"body": {
"queueStatus": "Active"
}
},
"error": null
}
]
}
]
},
"summary": {
"totalRequests": 4,
"totalPassed": 3,
"totalFailed": 1,
"duration": 450
}
}
License
This project is licensed under the MIT License.