Jmeter:测试计划有两个线程组,但它只生成了 1 个 jtl 报告

Jmeter: Test plan has two thread groups but it generated only 1 jtl report

我的 Jmeter 测试计划有两个线程。两个线程都需要单独的 CSV(csv 参数化)文件。

在测试结束时 mvn verify 我希望生成两个 .jtl 文件,但只得到一个。似乎只有 1 个线程是 运行ning。当我在 GUI 中 运行 时它工作正常,没有 maven。

测试计划:

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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo.performancetesting</groupId>
    <artifactId>demo-performance-testing</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <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>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>de.codecentric</groupId>
                <artifactId>jmeter-graph-maven-plugin</artifactId>
                <version>0.1.0</version>
                <configuration>
                    <inputFile>${project.build.directory}/jmeter/results/*.jtl</inputFile>
                    <graphs>
                        <graph>
                            <pluginType>ResponseTimesOverTime</pluginType>
                            <width>800</width>
                            <height>600</height>
                            <outputFile>${project.build.directory}/jmeter/results/BlazeDemoRequest.png</outputFile>
                        </graph>
                    </graphs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我已经浏览过这些帖子,但运气不好:

Can we run two thread groups parallely in a single test plan in Jmeter?

Why only 2 out 3 JMeter Thread group execute?

我正在使用 Windows 7、Maven 3、Jmeter Maven 插件

为什么你期望生成 2 个 jtl 文件,因为你没有任何侦听器。

在这种情况下,在非 gui 模式下,jmeter 只会生成 1 个文件,这就是 jmeter-maven-plugin 所做的。

顺便说一下,您使用的插件是旧版本 2.1.0,最后一个是 2.7.0。

在调试我的问题时,我发现第二个线程甚至无法在 GUI 模式下工作。然后我将 .csv 文件从线程 1 切换到线程 2,发现只有 1 个 .csv 文件总是有效。最后,在进一步挖掘之后,我发现为了 运行 你的 .csv 需要在 src/test/jmeter/testdata 文件夹中而不是在 apache-jmeter-3.2/bin/testdata.

答案: 第二个线程没有工作,因为它使用了不正确的 .csv。要找到它,请单击 Jmeter GUI 右上角的黄色三角形。它切换日志显示。这些日志显示 .csv 未找到的错误。

是的,我也遇到过一些在线论坛,他们会告诉您将 .csv 放在 apache-jmeter-3.2\bin\testdata 中,以便路径保持相对,即不依赖于项目结构或 OS。这是Jmeter中的CSV参数化。

所以,我建议两者都尝试,对我来说它在 src/test/jmeter/testdata 而不是 Jmeter bin 文件夹中工作。

您将仅在 2 种情况下生成 2 个 .jtl 文件:

  1. 您在 src/test/jmeter 文件夹下有 2 个 .jmx 脚本
  2. 您启用 Aggregate Report listeners and configure them to save results to ../results folder prefixed by the test name or __threadGroupName() (the function is available since JMeter 5.0)

一般情况下,如果 JMeter 测试出现任何意外行为,请习​​惯查看 jmeter.log 文件,如果 JMeter 测试通过 Maven 插件执行,则日志文件位于 target/jmeter/logs 文件夹下,相对于您的主 pom.xml 文件。通常它应该包含足够的故障排除信息以找到问题的根源。 JMeter 测试或线程组未执行的最常见原因是:

  • 提供的线程数不正确(即参数化失败)
  • 依赖文件丢失(即 CSV 文件不在预期位置)

您可以在 运行ning 测试时禁用所有侦听器,因为这是建议的。

  1. 只需添加一个 "Simple Data Writer" 侦听器并提供保存结果的位置。推荐使用 .jtl 文件类型的文件名。
  2. 如果你想要 2 个 .jtl 文件,你可以在每个线程组中添加这个侦听器。如果您想要汇总结果,请在测试计划级别添加此侦听器。
  3. 测试 运行 完成后,您可以将此 .jtl 文件浏览到您想要的任何所需的侦听器中,它工作正常。