A serverless project that executes postman tests via newman in AWS lambda and writes test results to cloudwatch logs using winston. The lamdba will return with an error if the test fails / does not complete.
First, install all node dependencies
npm install
Make sure to have the serverless framework installed.
Deploy the serverless project with
serverless deploy
You can invoke the function and validate if everything works with
serverless invoke -f run-newman-test
The lambda should return "Test run passed!"
if everything works as expected. (The project executed the test collection available in /testsuites
in newman and all tests passed)
The project uses the node config module for configuration. Hence, check out default.json
for default config options and custom-environment-variables.json
for available environment variables.
Every test-run generates a new environment based on environment variables specified in the configuration or through the event of the lamdba function.
All variables specified under testEnvironmentVariables
are passed to the test as specified in config/default.json
.
Variables provided under the key testEnvironmentVariables
of the lambda evnet are passed to the test. If a variable is specified in both the config file and in the lambda event, the value in the lambda event will overwrite the value specified in the config file.
Example of a lambda event containting environment variables for a test-run:
{
"testEnvironmentVariables": {
"myEnvVar": "abcd"
}
}
This project uses a custom winston-logger based reporter to optimize test result outputs for cloudwatch logs (the default logger would not write anything to cloudwatch logs). Check out https://github.com/Mgutjahr/newman-reporter-winston for additional details