【问题标题】:Run Jmeter tests with direct call only仅使用直接调用运行 Jmeter 测试
【发布时间】:2020-01-23 23:18:40
【问题描述】:

我将 Jmeter 插件添加到我的项目中,现在它的负载测试与 maven 构建一起运行。

  <!-- Jmeter  -->
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.9.0</version>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

我希望 Jmeter 测试只需运行以下命令即可运行:

mvn jmeter:jmeter -Pjmeter

我不希望它在执行任何 maven 生命周期时运行,例如:

mvn install

由于测试是在 Restful API 中执行的,因此负载测试将在每次运行 maven 生命周期时执行 POST 并在数据库中创建数据。

有人可以帮我吗?

【问题讨论】:

    标签: java maven testing jmeter


    【解决方案1】:

    只需将您的JMeter Maven Plugin 声明放在jmeter profile 下即可:

    <profiles>
        <profile>
            <id>jmeter</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.lazerycode.jmeter</groupId>
                        <artifactId>jmeter-maven-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <!-- Generate JMeter configuration -->
                            <execution>
                                <id>configuration</id>
                                <goals>
                                    <goal>configure</goal>
                                </goals>
                            </execution>
                            <!-- Run JMeter tests -->
                            <execution>
                                <id>jmeter-tests</id>
                                <goals>
                                    <goal>jmeter</goal>
                                </goals>
                            </execution>
                            <!-- Fail build on errors in test -->
                            <execution>
                                <id>jmeter-check-results</id>
                                <goals>
                                    <goal>results</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    

    只有当你明确指定jmeter配置文件时,才会执行JMeter maven插件

    演示:

    更多信息:

    【讨论】:

    • 对我来说,它通过将标签 &lt;phase&gt; jmeter &lt;/phase&gt; 放在标签 &lt;execution&gt; 中来工作,如示例中所示:&lt;execution&gt; &lt;id&gt;jmeter-tests&lt;/id&gt; &lt;phase&gt;jmeter&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;jmeter&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt;
    猜你喜欢
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多