如何通过maven项目生成jmeter仪表板报告

时间:2016-11-05 06:26:19

标签: jmeter jmeter-maven-plugin

我可以使用此命令jmeter -g /path/to/jtl/file -o /where/you/want/to/store/dashboard手动生成Jmeter仪表板报告 但我想通过maven项目生成它。

有什么办法吗?

以下是插件ex:

<goals>
<goal>jmeter</goal>
</goals>
<configuration>
    <propertiesUser>
    <jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format>
    <jmeter.save.saveservice.bytes>true</jmeter.save.saveservice.bytes>
    <jmeter.save.saveservice.label>true</jmeter.save.saveservice.label>
    <jmeter.save.saveservice.latency>true</jmeter.save.saveservice.latency>
    <jmeter.save.saveservice.response_code>true</jmeter.save.saveservice.response_code>
    <jmeter.save.saveservice.response_message>true</jmeter.save.saveservice.response_message>
    <jmeter.save.saveservice.successful>true</jmeter.save.saveservice.successful>
    <jmeter.save.saveservice.thread_counts>true</jmeter.save.saveservice.thread_counts>
    <jmeter.save.saveservice.thread_name>true</jmeter.save.saveservice.thread_name>
    <jmeter.save.saveservice.time>true</jmeter.save.saveservice.time></propertiesUser>
<propertiesSaveService>
    <output_format>csv</output_format>
</propertiesSaveService>

2 个答案:

答案 0 :(得分:0)

首先,您需要配置JMeter Maven插件,以适合HTML Reporting仪表板生成的格式存储测试结果,即将以下几行添加到 pom.xml 文件中:

<jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format>
<jmeter.save.saveservice.bytes>true</jmeter.save.saveservice.bytes>
<jmeter.save.saveservice.label>true</jmeter.save.saveservice.label>
<jmeter.save.saveservice.latency>true</jmeter.save.saveservice.latency>
<jmeter.save.saveservice.response_code>true</jmeter.save.saveservice.response_code>
<jmeter.save.saveservice.response_message>true</jmeter.save.saveservice.response_message>
<jmeter.save.saveservice.successful>true</jmeter.save.saveservice.successful>
<jmeter.save.saveservice.thread_counts>true</jmeter.save.saveservice.thread_counts>
<jmeter.save.saveservice.thread_name>true</jmeter.save.saveservice.thread_name>
<jmeter.save.saveservice.time>true</jmeter.save.saveservice.time>

我认为最简单的方法是使用Exec Maven Plugin,例如:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <phase>verify</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>-jar</argument>
            <argument>${basedir}/target/jmeter/bin/ApacheJMeter-3.0.jar</argument>
            <argument>-g</argument>
            <argument>${basedir}/target/jmeter/results/${maven.build.timestamp}-example.jtl</argument>
            <argument>-o</argument>
            <argument>${basedir}/target/dashboard</argument>
        </arguments>
    </configuration>
</plugin>

您可能需要将reportgenerator.properties文件和report-template文件夹复制到Maven项目的“target / jmeter / bin”目录(它不会在“干净”阶段存活)或复制属性,因为它在Adding Additional Properties To 章节中描述。

有关执行JMeter测试的不同选项的更多信息,请参阅Five Ways To Launch a JMeter Test without Using the JMeter GUI文章

答案 1 :(得分:0)

这是我用mvn使用mvn ant插件创建HTML报告的方法。

我的report-templatereportgenerator.properties位于src/testresources下。

    <plugins>
        <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>2.0.3</version>
            <configuration>
                <testResultsTimestamp>false</testResultsTimestamp>
                <propertiesUser>
                    <jmeter.save.saveservice.output_format>csv</jmeter.save.saveservice.output_format>
                    <jmeter.save.saveservice.bytes>true</jmeter.save.saveservice.bytes>
                    <jmeter.save.saveservice.label>true</jmeter.save.saveservice.label>
                    <jmeter.save.saveservice.latency>true</jmeter.save.saveservice.latency>
                    <jmeter.save.saveservice.response_code>true</jmeter.save.saveservice.response_code>
                    <jmeter.save.saveservice.response_message>true</jmeter.save.saveservice.response_message>
                    <jmeter.save.saveservice.successful>true</jmeter.save.saveservice.successful>
                    <jmeter.save.saveservice.thread_counts>true</jmeter.save.saveservice.thread_counts>
                    <jmeter.save.saveservice.thread_name>true</jmeter.save.saveservice.thread_name>
                    <jmeter.save.saveservice.time>true</jmeter.save.saveservice.time>
                </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>verify</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>
    </plugins>