使用 JMeter-Maven 插件运行 JMeter 脚本时出现错误“生成报告时出错:java.lang.NullPointerException”

Nah*_*hor 1 jmeter pom.xml jmeter-maven-plugin jmeter-5.0

使用 JMeter-Maven 插件运行 JMeter 脚本时收到错误“生成报告时出错:java.lang.NullPointerException”。

下面是我收到的错误的屏幕截图: 错误图像

下面是我的 pom.xml 文件:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.branch.performance simpleAccess 0.0.1-SNAPSHOT

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!--Access Portal Login page URL -->
    <AccessLoginPageURL>test-login.com</AccessLoginPageURL>
    <!-- base URL -->
    <BaseURL>test.branch.com</BaseURL>
    <!-- Number of users to simulate to execute the performance test plan -->
    <numberOfUsers>3</numberOfUsers>
    <!-- Time in seconds to get all users activated -->
    <rampupTimeInSeconds>1</rampupTimeInSeconds>
    <!-- Number of times the plan executed by every user -->
    <numberOfLoops>1</numberOfLoops>
    <apdexSatisfiedThreshold>2000</apdexSatisfiedThreshold>
    <apdexToleratedThreshold>4000</apdexToleratedThreshold>
    <!-- JMeter Dashboard output file report name -->
    <jmeterReportTitle>Performance Dashboard</jmeterReportTitle>
</properties>


<build>
    <plugins>
        <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>3.0.0</version>


            <executions>
                <execution>
                    <id>configuration</id>
                    <goals>
                        <goal>configure</goal>
                    </goals>
                </execution>
                <execution>
                    <id>jmeter-tests</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>jmeter</goal>
                    </goals>
                </execution>
                <execution>
                    <id>jmeter-check-results</id>
                    <goals>
                        <goal>results</goal>
                    </goals>
                </execution>
            </executions>

            <configuration>
                    <junitLibraries>
                        <artifact>mysql:mysql-connector-java:8.0.18</artifact>
                    </junitLibraries>
                <testFilesIncluded>

                    <jMeterTestFile>MyTestFile.jmx</jMeterTestFile>
                </testFilesIncluded>
                <testResultsTimestamp>false</testResultsTimestamp>
                <propertiesUser>
                    <AccessLoginPageURL>${LoginPageURL}</AccessLoginPageURL>
                    <BaseURL>${BaseURL}</BaseURL>
                    <numberOfUsers>${numberOfUsers}</numberOfUsers>
                    <rampupTimeInSeconds>${rampupTimeInSeconds}</rampupTimeInSeconds>
                    <numberOfLoops>${numberOfLoops}</numberOfLoops>
                    <jmeter.reportgenerator.apdex_satisfied_threshold>${apdexSatisfiedThreshold}</jmeter.reportgenerator.apdex_satisfied_threshold>
                    <jmeter.reportgenerator.apdex_tolerated_threshold>${apdexToleratedThreshold}</jmeter.reportgenerator.apdex_tolerated_threshold>
                    <jmeter.reportgenerator.report_title>${jmeterReportTitle}</jmeter.reportgenerator.report_title>
                    <!-- if below is true then doesn't show summary of events in console log -->
                    <summariser.ignore_transaction_controller_sample_result>false</summariser.ignore_transaction_controller_sample_result>
                    <jmeter.save.saveservice.subresults>true</jmeter.save.saveservice.subresults>
                    <!-- Generate JMeter report with only transaction labels and data without sub samplers -->
                    <!--jmeter.reportgenerator.exporter.html.show_controllers_only>true</jmeter.reportgenerator.exporter.html.show_controllers_only-->                      
                </propertiesUser>
                <generateReports>true</generateReports>
            </configuration>
        </plugin>
    </plugins>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>3.0.0-M4</version>
        </plugin>
    </plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud)

Dmi*_*i T 5

您的测试未成功执行:

在此输入图像描述

因此结果文件为空,因此 JMeter 无法生成HTML 报告仪表板

实际上,未正确处理的NPE表明代码中存在大问题,因为 yoiu 通常不应该在或多或少成熟的软件中看到类似的问题,因此您可以通过JMeter Bugzilla报告该问题,因为 JMeter 不应该抛出 NPE,它应该报告一条人类可读的消息,表明结果文件为空,建议检查 jmeter.log 文件以找出可能的原因。

因此,您应该在文件夹下看到your_test_script_name.jmx.log文件target/jmeter/logs,我非常确定您会在那里找到测试脚本失败的根本原因。

查看如何使用 JMeter Maven 插件文章,了解有关通过 Apache Maven 运行 JMeter 测试的更多信息

  • 嗨德米特里,感谢您的回复!由于我弄乱了 csv 文件路径,问题得到了解决。 (2认同)