Using jmeter
in a bash script, how can I manage that it returns a non zero value if any assertion failed?
jmeter -n -t someFile.jmx
echo $?
# always returns 0, even if an assertion failed
I tried with a Bean Shell Assertion
using the script:
if (ResponseCode.equals("200") == false) {
System.exit(-1);
}
But this does not even return 0
, it just kills the process (I guess?)
May anyone help me with this?
Exit Status Each shell command returns an exit code when it terminates, either successfully or unsuccessfully. By convention, an exit code of zero indicates that the command completed successfully, and non-zero means that an error was encountered. The status code can be used to find out why the command failed.
To set an exit code in a script use exit 0 where 0 is the number you want to return. In the following example a shell script exits with a 1 . This file is saved as exit.sh . Executing this script shows that the exit code is correctly set.
Exit status 0 It tells you that your latest command or script executed successfully. Success is relative because the exit code only informs you that the script or command executed fine, but the exit code doesn't tell you whether the information from it has any value.
Put the following code in JSR223 Element
System.exit(1);
It will return error level 1
which will be displayed in Linux when executing echo $?
In case you only care about jmeter returning exit code when errors are found, you can check the .log for lines with error afterwards:
test $(grep -c ERROR jmeter.log) -eq 0
If you call echo $?
, you can see it returns 1 if errors are found and 0, if not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With