Jmeter 测试 运行 使用 maven

Jmeter test running using maven

我正在学习 jmeter 并尝试使用 Maven 配置它,但是当我 运行 "mvn verify -e"

时出现以下异常
    [ERROR] Failed to execute goal com.lazerycode.jmeter:jmeter-maven-     plugin:1.9.0:jmeter (jmeter-tests) on project jmeter: C:\qa\jmeter\target\jmeter\results150921-JmeterTests.jtl    (The system cannot find the file specified) -> [Help 1]
   org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.lazerycode.jmeter:jmeter-maven-plugin:1.9.0:jmeter (jmeter-tests) on project jmeter: C:\hass-git\cpp_ocp2\cpp_ocp2\qa\jmeter\target\jmeter\results150921-JmeterTests.jtl (The system cannot find the file specified)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
   Caused by: org.apache.maven.plugin.MojoExecutionException: C:\qa\jmeter\target\jmeter\results150921-JmeterTests.jtl (The system cannot find the file specified)
    at com.lazerycode.jmeter.JMeterMojo.parseTestResults(JMeterMojo.java:75)
    at com.lazerycode.jmeter.JMeterMojo.execute(JMeterMojo.java:54)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more

我的pom.xml有

    <build>
    <plugins>
        <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-maven-plugin</artifactId>
            <version>1.9.0</version>
            <executions>
                <execution>
                    <id>jmeter-tests</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>jmeter</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>

            </configuration>
        </plugin>
        <plugin>
            <groupId>com.lazerycode.jmeter</groupId>
            <artifactId>jmeter-analysis-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals>
                        <goal>analyze</goal>
                    </goals>
                    <configuration>

                        <source>${project.build.directory}/**/*.jtl</source>


                        <targetDirectory>${project.build.directory}/results</targetDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我的文件夹结构是

  qa/jmeter/src/test/jmeter/jmeterTests.jmx

执行 mvn -e -X verify,以查看更多输出、一切顺利以及发生错误的位置、时间和原因。

再次将这些选项添加到您的 jmeter-maven-plugin 和 运行 jmeter 脚本中。希望能显示更多细节,关于什么时候到底出了什么问题。目前看起来输出文件没有写入等等...

<configuration>
    <!-- By default the test results are saved in a file /target/jmeter/results/<testname>-<timestamp>.jtl 
        Further processing is easier without timestamp though. -->
    <testResultsTimestamp>false</testResultsTimestamp>

    <!-- To simplify debugging, it is advisable to adapt the loglevel. The 
        jmeter logs are written to the file jmeter.log. -->
    <overrideRootLogLevel>DEBUG</overrideRootLogLevel>

    <!-- By default, the console output during a jmeter test run is suppressed. 
        We want to display the progress using the listener "Generate Summary Results" 
        (which periodically prints stats to stdout). Therefore we have to make sure, 
        that the jmeter output is not suppressed. -->
    <suppressJMeterOutput>false</suppressJMeterOutput>

    <!-- If tests fail (e.g. a http-request running into a timeout), the corresponding 
        maven goal also fails (and subsequent goals aren't executed anymore). We 
        want to create graphs from test-results, no matter if some requests failed 
        or not, so we ignore jmeter failures. -->
    <ignoreResultFailures>true</ignoreResultFailures>
</configuration>

提示:使用最新的jmeter-maven-plugin(当前版本1.10.1)