To setup JMeter + Maven project in eclipse please refer post
Running JMeter Script from Eclipse in Maven project
We can create HTML report for Maven JMeter Test by following below points:
- Create a source folder named src/test/resources
- Copy/Paste reportgenerator.properties and report-template file/folder from JMeter/bin directory to src/test/resources
- Update POM with CSV output_format property and add maven-antrun-plugin
- Script Execution
- HTML Report
Create New Source Folder
- Project > Build Path > New Source Folder
- Provide Folder name > src/test/resources
- Project Hierarchy after folder creation
- Copy/Paste reportgenerator.properties and report-template file/folder from apache-jmeter-x.x/bin directory to src/test/resources
- Project Hierarchy after pasting above file/folder
Update POM
- Report generation requires csv output format, so we need to add 'jmeter.save.saveservice.output_format' jmeter property
<jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format>
- Add maven-antrun-plugin and define task.
Also, Please make sure your version of Apache JMeter Jar and add it accordingly to POM
${basedir}/target/jmeter/bin/ApacheJMeter-3.1.jar version
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>pre-site</phase>
<configuration>
<tasks>
<delete dir="${basedir}/target/jmeter/results/dashboard" />
<mkdir dir="${basedir}/target/jmeter/results/dashboard" />
<copy file="${basedir}/src/test/resources/reportgenerator.properties"
tofile="${basedir}/target/jmeter/bin/reportgenerator.properties" />
<copy todir="${basedir}/target/jmeter/bin/report-template">
<fileset dir="${basedir}/src/test/resources/report-template" />
</copy>
<java jar="${basedir}/target/jmeter/bin/ApacheJMeter-3.1.jar" fork="true">
<arg value="-g" />
<arg value="${basedir}/target/jmeter/results/*.jtl" />
<arg value="-o" />
<arg value="${basedir}/target/jmeter/results/dashboard/" />
</java>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
- Complete POM
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>example</groupId> <artifactId>example</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>example</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>com.lazerycode.jmeter</groupId> <artifactId>jmeter-maven-plugin</artifactId> <version>2.1.0</version> <configuration> <testResultsTimestamp>false</testResultsTimestamp> <propertiesUser> <threads>${threadCount}</threads> <rampup>${rampupTime}</rampup> <duration>${durationSecond}</duration> <jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format> </propertiesUser> </configuration> <executions> <execution> <id>jmeter-tests</id> <phase>verify</phase> <goals> <goal>jmeter</goal> </goals> </execution> </executions> </plugin> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>pre-site</phase> <configuration> <tasks> <delete dir="${basedir}/target/jmeter/results/dashboard" /> <mkdir dir="${basedir}/target/jmeter/results/dashboard" /> <copy file="${basedir}/src/test/resources/reportgenerator.properties" tofile="${basedir}/target/jmeter/bin/reportgenerator.properties" /> <copy todir="${basedir}/target/jmeter/bin/report-template"> <fileset dir="${basedir}/src/test/resources/report-template" /> </copy> <java jar="${basedir}/target/jmeter/bin/ApacheJMeter-3.1.jar" fork="true"> <arg value="-g" /> <arg value="${basedir}/target/jmeter/results/*.jtl" /> <arg value="-o" /> <arg value="${basedir}/target/jmeter/results/dashboard/" /> </java> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
Script Execution with Parameters
mvn verify -DthreadCount=20 -DrampupTime=5 -DdurationSecond=60 pre-site
Script Execution without Parameters
mvn verify pre-site
HTML Report will be available at
${basedir}/target/jmeter/results/dashboard/index.html
index.html file is not being generated.
ReplyDeleteindex.html file is not being generated for me also
ReplyDelete