微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JMeter + Maven in Jenkins

Environment prepares

  1. Write the JMeter scripts.
  2. Install Java, Jenkins, Maven environment in system.

Run JMeter scripts by Maven

  1. Create the Maven project and organize directory.
  2. copy the JMeter scripts into the src/test/jmeter directory. It's the default directory set by jmeter-maven-plugin which used to run script.
  3. copy the Property file into the src/test/jmeter directory. You can edit it to override JMeter's default properties.
  4. copy the resources to src/test/resources directory.

That's the screenshot:

  1. Edit the Pom.xml
    It's is the whole content in Pom.xml:
<?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>testops.top</groupId>
    <artifactId>Jmeter</artifactId>
    <version>1.0</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- Specify resources source dir-->
        <jmeter.resources.source.dir>${project.basedir}/src/test/resources</jmeter.resources.source.dir>
        <!-- Specify the resources output directory after build -->
        <jmeter.resources.output.dir>${project.build.directory}/jmeter/html</jmeter.resources.output.dir>
        <!-- Specify testFiles source dir-->
        <jmeter.testFiles.source.dir>${project.basedir}/src/test/jmeter</jmeter.testFiles.source.dir>
        <!-- JTL directory of jmeter test result -->
        <jmeter.result.jtl.dir>${project.build.directory}/jmeter/results</jmeter.result.jtl.dir>
        <!-- The stylesheet used for converting JTL to HTML-->
        <jmeter.result.html.dir>${project.build.directory}/jmeter/html</jmeter.result.html.dir>
        <jmeter.result.html.stylesheetFile>${jmeter.result.html.dir}/jmeter-results-detail-report_21.xsl
        </jmeter.result.html.stylesheetFile>

    </properties>
    <build>
        <plugins>
            <plugin>
                <!-- copy resources to the output directory -->
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <!-- here the phase you need -->
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${jmeter.resources.output.dir}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${jmeter.resources.source.dir}</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>3.4.0</version>
                <executions>
                    <!-- Generate JMeter configuration -->
                    <execution>
                        <id>configuration</id>
                        <goals>
                            <goal>configure</goal>
                        </goals>
                    </execution>
                    <!-- Run JMeter tests -->
                    <execution>
                        <id>jmeter-tests</id>
                        <phase>verify</phase>
                        <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>
                    <!-- Specify testFiles directory -->
                    <testFilesDirectory>${jmeter.testFiles.source.dir}</testFilesDirectory>
                    <!-- The JTL results directory -->
                    <resultsDirectory>${jmeter.result.jtl.dir}</resultsDirectory>
                    <!-- The Jar Extensions In Jmeter -->
                    <jmeterExtensions>
                        <artifact>kg.apc:jmeter-plugins-functions:2.1</artifact>
                        <artifact>MysqL:mysql-connector-java:8.0.23</artifact>
                    </jmeterExtensions>
                    <!-- The plugin uses some broken dependencies
                         An alternative is to set this to true and use excludedArtifacts, see below
                    -->
                    <downloadExtensionDependencies>false</downloadExtensionDependencies>
                    <!-- To set <generateReports> is used to make <resultsFileFormat> useful when it is "xml" -->
                    <generateReports>false</generateReports>
                    <resultsFileFormat>xml</resultsFileFormat>
                </configuration>
            </plugin>
            <plugin>
                <!-- Current plugin convert jlt in xml style to html -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>xml-maven-plugin</artifactId>
                <version>1.0.2</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>transform</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <transformationSets>
                        <transformationSet>
                            <dir>${jmeter.result.jtl.dir}</dir>
                            <stylesheet>${jmeter.result.html.stylesheetFile}</stylesheet>
                            <outputDir>${jmeter.result.html.dir}</outputDir>
                            <fileMappers>
                                <fileMapper
                                        implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                    <targetExtension>html</targetExtension>
                                </fileMapper>
                            </fileMappers>
                        </transformationSet>
                    </transformationSets>
                </configuration>
                <!-- using XSLT 2.0 -->
                <dependencies>
                    <dependency>
                        <groupId>net.sf.saxon</groupId>
                        <artifactId>saxon</artifactId>
                        <version>8.7</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

If you can't learn why it is or how to edit, you sould learn the follow kNowledges:

  • Maven Plugin: xml-maven-plugin, jmeter-maven-plugin, maven-resources-plugin
  1. Run scripts by mvn
mvn clean verify
  1. Read the Html Project


原文地址:https://www.cnblogs.com/testopsfeng/p/14852836.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐