【问题标题】:How to use Maven profiles in Jmeter如何在 Jmeter 中使用 Maven 配置文件
【发布时间】:2019-12-16 17:09:33
【问题描述】:

我有不同的环境,例如 prod、local、dev 和 QA 来进行性能测试。根据环境,我想更改线程、循环计数和域名值。通过使用 Jmeter 属性,我可以更改如下值

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

但我想通过使用 ma​​ven 配置文件 来更改此值。你能帮我解决一下吗。我花了很多时间,但我不知道如何在 Jmeter 中使用配置文件。

【问题讨论】:

    标签: java maven jmeter


    【解决方案1】:

    我希望在这里看到您的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

    【讨论】:

      猜你喜欢
      • 2019-03-26
      • 2012-08-06
      • 2018-03-02
      • 2012-01-02
      • 2014-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多