gpt4 book ai didi

java - 如何在 Jmeter 中使用 Maven 配置文件

转载 作者:行者123 更新时间:2023-12-01 19:20:36 24 4
gpt4 key购买 nike

我有不同的环境,如生产、本地、开发和质量检查来进行性能测试。根据环境,我想更改线程、循环计数和域名值。通过使用 Jmeter 属性,我可以更改如下值

mvn process-resources jmeter:jmeter jmeter-analysis:analyze -Dthreads=30 -DloopCount=30 -DdomainName=mydomainname

但我想通过使用ma​​ven 配置文件来更改此值。你能帮我一下吗?我花了很多时间,但我没有任何线索如何在 Jmeter 中使用配置文件。

最佳答案

我的期望是看到你的pom.xml将文件放在此处,以便我们可以向您指出错误。这也将证明您尝试解决问题,而不是要求社区为您完成工作。

根据Introduction to Build Profiles文档章节添加类似以下内容就足够了:

<profiles>
<profile>
<id>dev</id>
<properties>
<threads>50</threads>
<loopCount>50</loopCount>
<domainName>devDomain</domainName>
</properties>
</profile>
<profile>
<id>qa</id>
<properties>
<threads>1000</threads>
<loopCount>1000</loopCount>
<domainName>qaDomain</domainName>
</properties>
</profile>
</profiles>

为了相应地定义 devqa 环境的属性,因此当您通过 Maven 运行 JMeter 时,如下所示:

mvn -P dev verify

您将获得 50 个用户、50 个循环等。

如果您运行 qa 配置文件,例如:

mvn -P qa verify

您将获得 1000 个用户、1000 个循环等。

完整的 pom.xml 以防万一:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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.example</groupId>
<artifactId>jmeter</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<threads>100</threads>
<loopCount>100</loopCount>
<domainName>defaultDomain</domainName>
</properties>

<profiles>
<profile>
<id>dev</id>
<properties>
<threads>50</threads>
<loopCount>50</loopCount>
<domainName>devDomain</domainName>
</properties>
</profile>
<profile>
<id>qa</id>
<properties>
<threads>1000</threads>
<loopCount>1000</loopCount>
<domainName>qaDomain</domainName>
</properties>
</profile>
</profiles>

<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>
<configuration>
<propertiesUser>
<threads>${threads}</threads>
<loopCount>${loopCount}</loopCount>
<domainName>${domainName}</domainName>
</propertiesUser>
</configuration>
</plugin>
</plugins>
</build>

</project>

更多信息:How to Use the JMeter Maven Plugin

关于java - 如何在 Jmeter 中使用 Maven 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59361289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com