用maven执行jmeters junit采样器

时间:2017-06-20 15:11:52

标签: maven jenkins jmeter jmeter-maven-plugin

我想使用maven对jmeters junit采样器执行负载测试,并希望报告性能结果。我使用10个线程,上升时间为5秒。这是我的pom文件

enter code here   <properties>
        <selenium.version>3.0.1</selenium.version>      
    </properties>

    <dependencies>

        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>          
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.2.0</version>
                <executions>
                    <execution>
                        <id>jmeter-classes</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <junitLibraries>
                      <artifact>com.lazerycode.junit:junit-test:1.0.0</artifact>
                        </junitLibraries>
                    <propertiesGlobal>
                        <threads>10</threads>
                        <rampup>5</rampup>
                    </propertiesGlobal>
                </configuration>
            </plugin>
        </plugins>
    </build>

如果是正确的方式来拨打jmeter的junit请求采样器,请帮助我。如果没有请帮我修正。

另外,请帮助我如何报告效果结果(例如报告)

谢谢和问候

1 个答案:

答案 0 :(得分:0)

根据Adding additional libraries to the classpath文档的JMeter Maven Plugin章节,您应将依赖项置于<jmeterExtensions>标记下,如:

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

    <repositories>
        <repository>
            <id>your-junit-jar</id>
            <name>your junit repo</name>
            <url>file:/path/to/your-junit-jar.jar</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.2.0</version>
                <executions>
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <jmeterExtensions>
                        <artifact>org.seleniumhq.selenium:selenium-java:3.0.1</artifact>
                        <artifact>org.seleniumhq.selenium:selenium-firefox-driver:3.0.1</artifact>
                    </jmeterExtensions>
                    <junitLibraries>
                        <artifact>com.yourcompany.yourgroup:your-artifact:1.0-SNAPSHOT</artifact>
                    </junitLibraries>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

另请注意,WebDriver Sampler JMeter Plugin提供了与Selenium的无缝JMeter集成,因此您不必每次都重新编译Selenium代码并将其直接内联到.jmx文件中。