首页 > 其他 > 详细

JMeter + Maven in Jenkins

时间:2021-06-05 18:33:55      阅读:21      评论:0      收藏:0      [点我收藏+]

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
    技术分享图片
    技术分享图片

JMeter + Maven in Jenkins

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!