如何配置Jmeter maven插件以生成Jmeter 3.0报告仪表板

问题描述 投票:1回答:3

我无法使用Jmeter-maven-plugin版本2.0.3为Jmeter 3.0生成报告仪表板。我在Jmeter maven插件中的配置中添加并添加了jmeter.save.saveservice属性,但是我得到“确保jmeter.save.saveservice。*属性与创建CSV文件时相同或者可以读取文件执行后尝试创建报表控制板时出错“错误”。

我还在我的src / test / jmeter文件夹中添加了Jmeter.properties和user.properties,我看到这些属性在执行后会添加到目标文件夹中的这些文件中。

有些人可以告诉我pom应该如何,以便我们可以自动为Jmeter 3.0创建报告仪表板。

谢谢

jmeter maven-plugin jmeter-maven-plugin
3个回答
3
投票

以下是步骤 -

  • 从jmeter bin目录复制report-template reportgenerator.reporties并将其保存在src/test/resourcesfolder中
  • 在你的pom中添加maven-antrun-plugin如下 -

<plugin>
 <artifactId>maven-antrun-plugin</artifactId>
  <executions>
   <execution>
    <phase>pre-site</phase>
     <configuration>
      <tasks>
       <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.0.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>

运行负载测试后,您可以执行mvn pre-site,它将在target\jmeter\results\dashboard下生成测试JMeter仪表板

参考 - http://www.testautomationguru.com/jmeter-continuous-performance-testing-jmeter-maven/

更多的东西 - 我不使用maven jmeter analysis,因为html仪表板远比这更好。因此,我生成csv格式的测试结果,这比xml资源更少。我使用以下shell脚本将CI作业标记为在运行测试并生成报告后测试失败后失败 -

if grep false ${WORKSPACE}/prototype/target/jmeter/results/TestPlanNew.jtl; then
echo "Test Failures!!! please check "${WORKSPACE}/prototype/target/jmeter/results/TestPlanNew.jtl" file"
exit 1
fi

0
投票

我想建议修改/添加@Tarun的答案,因为我在运行mvn pre-site时遇到以下错误:

[java] An error occurred: Cannot read test results file :.../target/jmeter/results/*.jtl

它与使用通配符作为结果文件名有关。如果您需要.jtl文件的动态文件名,那么您也可以复制该文件并为其指定静态名称。例如,通过将以下<copy>块包含到<tasks>中:

<mkdir dir="${basedir}/target/jmeter/results/tmp" />
<copy todir="${basedir}/target/jmeter/results/tmp">
    <fileset dir="${basedir}/target/jmeter/results/" >
        <include name="**/*.jtl"/>
    </fileset>
    <globmapper from="*" to="result.jtl" />
</copy>

并相应地调整-g参数的值

<arg value="${basedir}/target/jmeter/results/tmp/result.jtl" />

最后,在为JMeter(3.1)包含org.slf4j:slf4j-simple:1.7.21依赖(版本可能随时间变化)之后,它按预期工作并生成HTML Dashboard。


0
投票

使用最新版本的plugin,它将通过默认配置生成。

示例pom.xml:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.foo</groupId>
    <artifactId>test</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>training-project</name>
    <url>http://maven.apache.org</url>
    <dependencies>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.6.0</version>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jmeter-tests2</id>
                        <goals>
                            <goal>results</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generateReports>true</generateReports>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
© www.soinside.com 2019 - 2024. All rights reserved.