Vineet Raman
Vineet Raman

Reputation: 11

How to Fail a Maven Build if JMeter Test Performance Exceeds a Threshold? (jmeter-maven-plugin)

I'm using the jmeter-maven-plugin in my Maven project to run JMeter tests. I want to fail the build if any of the JMeter test metrics exceed specified performance thresholds (e.g., response time).

Here’s the relevant section of my pom.xml:

com.lazerycode.jmeter jmeter-maven-plugin 3.5.0 configuration configure jmeter-tests verify jmeter jmeter-check-results results xml false false true ${project.base.directory} proxy.host 8080 org.codehaus.mojo xml-maven-plugin 1.0 verify transform

target/jmeter/results src/test/jmeter/jmeter-results-to-junit.xsl target/surefire-reports (.*?)\s(.*?) $1$2 true .xml

Problem: I need to ensure that the Maven build fails if the JMeter tests exceed certain performance thresholds (e.g., response time > 2000 ms). How can I configure the jmeter-maven-plugin to include this check and fail the build accordingly?

Any guidance on how to achieve this would be greatly appreciated!

Additional Details: I am using the jmeter-maven-plugin version 2.7.0. I want to check specific metrics from the JMeter test results. The results are being generated in XML format.

Upvotes: 1

Views: 60

Answers (2)

Vineet Raman
Vineet Raman

Reputation: 11

  1. Add Execution for jmeter-check-results: Include the following execution in your pom.xml under the jmeter-maven-plugin:

<execution>
    <id>jmeter-check-results</id>
    <goals>
        <goal>results</goal>
    </goals>
</execution>

  1. Set Configuration Properties to Check Results and Fail the Build: Configure the properties to check the results and fail the build if the error rate exceeds 10%:

<ignoreResultFailures>false</ignoreResultFailures> 

<errorRateThresholdInPercent>0.1</errorRateThresholdInPercent>

By adding these configurations, the build will check the JMeter test results and fail if the error rate is higher than the specified threshold (10% in this case).

Upvotes: 0

Ivan G
Ivan G

Reputation: 2872

Take a look at Duration Assertion, you can add it to your test and configure it to fail Sampler(s) in its scope if their response time exceeds 2000 ms the Maven Plugin will fail the build and return non-zero exit status code.

More information on conditionally failing JMeter requests using various pass/fail criteria: How to Use JMeter Assertions in Three Easy Steps

Upvotes: 0

Related Questions