Nikolay Marinov
Nikolay Marinov

Reputation: 121

Jmeter Test Plan summary report PASS/FAIL

I'm stuck on finding solution on one problem with Jmeter. I need to put some logic into my Test Plan that can give simple report PASS/FAIL calculated on test cases execution results and put in generated JTL report afterwards. For instance

  1. All tests passed - Test Plan result=PASS
  2. One or more tests failed - Test Plan result=FAIL

Upvotes: 0

Views: 3243

Answers (2)

Iske
Iske

Reputation: 1200

Add one BeanShell Listener and one BeanShell Sampler at the end of your Thread Group and put this in Listener:

if(sampleEvent.getResult() instanceof org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)
    if (!sampleEvent.getResult().isResponseCodeOK())
            vars.put("res", -1);

And in BS Sampler put:

  • if you wanna store result as property:

props.put("testPlanResult", vars.get("res") != -1 ? "PASS" : "FAIL");

  • if you wanna store result in a file:
f = new FileOutputStream("/path/to/file.txt", false);
p = new PrintStream(f); 

p.println("Result: " + (vars.get("res") != -1 ? "PASS" : "FAIL"));

p.close();
f.close();

From here you can do what ever you need with created property or file containing result...

Hope this helps you!

EDIT:

You will need to add this import if writing result to file:

import org.apache.jmeter.services.FileServer;

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168072

The majority of suitable options assume using third-party tools, to wit:

  • you can run JMeter test in Jenkins and use Performance plugin, it allows to conditionally fail the build if the amount of failed requests exceeds specified threshold

    Jenkins performance plugin

  • you can run JMeter test using Taurus tool as a wrapper, it has flexible and powerful Pass/Fail Criteria Subsystem allowing to set different criteria definitions to mark the test as passed or failed. If build is failed Taurus process returns non-zero exit code.

If above approaches are not suitable for any reason please elaborate your question and explain how and where you would like to see this "FAIL" or "PASS" result.

Upvotes: 0

Related Questions