Fredrik
Fredrik

Reputation: 10656

Fail test on Exception in JSR223 postprocessor

In my Jmeter (2.13) I have a piece of Java code in a JSR223 postprocessor. The code throws a Nullpointerexception, but the test will still report ok.

How can I report a failed Jmeter test when an exception occurs?

Upvotes: 3

Views: 2724

Answers (1)

Dmitri T
Dmitri T

Reputation: 168157

You can do it by calling the following code line:

prev.setSuccessful(false);

Example usage:

try {
    //your code here
}
catch (Throwable ex) {
    log.error("Failure", ex);
    prev.setSuccessful(false);
    prev.setResponseMessage(ex.getMessage());
    throw ex;
}

prev is a shorthand to SampleResult class instance, it provides read/write access to all associated SampleResult methods and fields.

See How to Use BeanShell: JMeter's Favorite Built-in Component article to learn more about using Java and JMeter API from scripting test elements. Pre-defined variables like prev, vars, ctx and so on are common for all scripting test elements.

Upvotes: 6

Related Questions