Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is there an option to make the newman execution fail if it did not run any tests? #3164

Open
sudhirbits opened this issue Oct 20, 2023 · 1 comment

Comments

@sudhirbits
Copy link

Is there an option to make the newman execution fail if it did not run any tests?

@AnshSinghSonkhia
Copy link

Hey @sudhirbits,
Newman doesn't have a built-in option to fail the execution explicitly if no tests are run.
However, you can achieve this by incorporating some scripting or checking mechanisms in your workflow.

So, after Newman execution we can use a script to check the number of executed tests from the report. If zero tests were run, set a non-zero exit code for the script, indicating failure.

Something like this:

# Run Newman and save the result in a variable
NEWMAN_RESULT=$(newman run your_collection.json -e your_environment.json)

# Check if there are any test failures in the Newman result
if echo "$NEWMAN_RESULT" | grep -q "failures="; then
  echo "Tests failed."
  exit 1  # Exit with a non-zero status to indicate failure
else
  echo "Tests passed."
fi

Another option could be:

While using a CI/CD tool, configure it to fail the build based on the Newman exit code or specific keywords in the output (e.g., "0 tests executed").

hope it helps :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants