Maven JMeter plugin and report generation (the last steps to get it working)

9

JMeter (http://jakarta.apache.org/jmeter/)is a powerful tool for functional and performance testing web applications. JMeter, opposed to selenium, also works perfectly on generated applications (like Oracle ADF ). One of the key strengths of JMeter is the automation. The same test can be repeated after each (minor) release. This is a great help in executing time consuming regression testing.

We use Maven 2 (http://maven.apache.org/) in combination with Continuum (http://maven.apache.org/continuum/) as the basis of our AMIS-SoftwareStudio. With the build schema in Continuum we are able to execute both performance and functional regression testing every night (or even each hour if you like) on the most recent version of the application from our source repository.

The documentation on the JMeter wiki (http://wiki.apache.org/jakarta-jmeter/JMeterMavenPlugin) is to limited to get the JMeter plugin working at once. It does not handle the generation of reports and installing the plugin into your company repository. Most of the samples on the internet (use the Google to find Maven 2+JMeter) are based on extensive Ant scripts. The sample below shows how to get the Maven-JMeter-Plugin working in Maven2 with a minimum of extra code in your projects pom.xml.

Assume you have:

  • Java 1.5 and Maven 2.0.7 already installed
  • An internal central Maven2 repository in your network
  • And your maven settings.xml a reference to your local company repository (see below)

Add to settings.xml

<…>
<distributionManagement>
    <!--   Internal repository for deployment of AMIS artifacts -->
    <repository>
      <id>AMISMaven2Repo</id>
      <!--   Put the name of your company repository here-->
      <url>file:\\mavenrepository.amis.nl\maven2</url>
    </repository>
</distributionManagement>
<….> 

Install the Maven-JMeter-Plugin:

Install the plugin:
1.    Download the Maven-Jmeter-Plugin form the apache wiki (there is no official distribution yet)  Link here.
2.    Untar these files with e.g. WinRar or WinZip.
3.    Edit the pom.xml:

a.    Remove the reference to the yahoo music repository
b.    Add a compile plugin to force usage of jdk1.5 (to avoid compile errors)
The pom.xml should look like this (Link download):

4.    Go to the maven-jmeter-plugin folder and deploy the plugin in your local company repository:   mvn deploy (you can check first  if it works by using mvn install)

5.    The Maven JMeter plugin is now installed and available in your internal repository.

 Getting your project working with the JMeter plugin:

 This section is an extension on the information from the JMeter Wiki.

  1. Create a src/test/jmeter directory, and place your JMeter load tests there.
  2. Create a jmeter.properties file in src/test/jmeter. Just copy the default properties file from the JMeter install.
  3. Edit the jmeter.properties  and change the jmeter.save.saveservice.output_format to XML (jmeter.save.saveservice.output_format=xml) to force JMeter to produce XML files in stead of CSV files.
  4. Optionally configure includes and excludes in your pom.xml for which tests to run. If you don’t, it will just run **/*.jmx.
  5. Add a reference to http://maven.geotools.org/repository/ in your pom. This is some place where maven can download jmeter-2.2.jar. (other locations are also valid (use the Google)).  
  6. Add the Maven JMeter plugin and link it to the Verify phase of your project. This way it is automatically executed after deployment of the application on the target platform.
  7. Run the mvn verify command to start the JMeter tests.
        
    <build>
     <...>
       <plugins>
        <plugin>
           <groupId>org.apache.jmeter</groupId>
           <artifactId>maven-jmeter-plugin</artifactId>
          <executions>
                     <execution>
                         <phase>verify</phase>
                         <id>jmeter-tests</id>
                         <configuration>
                           <includes>
                            <include>amistest.jmx</include>
                           </includes>
                           <reportDir>target/jmeter-reports</reportDir>
                         </configuration>
                         <goals>
                             <goal>jmeter</goal>
                         </goals>
                     </execution>
                 </executions>
         </plugin>
       <plugins>
      <...>
    </build> 

Creating the JMeter results report:

This section explains how to generate a JMeter Report after executing the tests.
 

  1. Create a test_resources\jmeter\jakarta-jmeter-2.2\extras folder and add the following files form the JMeter Extras install: collapse.jpg; expand.jpg; jmeter-results-detail-report_21.xsl ; jmeter-results-report_21.xsl
  2. Add the xml-maven-plugin to force transition of the jmeter results.xml to HTML.
  3. Use the Filemapper option to rename the files to HTML
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>xml-maven-plugin</artifactId>
         <executions>
           <execution>
             <phase>pre-site</phase>
             <goals>
               <goal>transform</goal>
             </goals>
           </execution>
         </executions>
         <configuration>
             <transformationSets>
             <transformationSet>
               <dir>src/test/jmeter/testresults</dir>
               <stylesheet>test_resources/jmeter/jakarta-jmeter-2.2/extras/jmeter-results-detail-report_21.xsl</stylesheet>
               <outputDir>target/site/jmeter-results</outputDir>
                <fileMappers>
                 <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                 <targetExtension>html</targetExtension>
                </fileMapper>
               </fileMappers>
           </transformationSet>
          </transformationSets>
       </configuration>
    </plugin>

 

4.    Finally use antrun to copy the expand and collaps images to the generated target files. (see sample below)

5.    In continuum you can use the command mvn verify site-deploy to run the jmeter tests and deploy the results within the project site.

<!-- make sure the jmeter icons are copied to the site folder -->
  <plugin>
              <artifactId>maven-antrun-plugin</artifactId>
              <executions>
               <execution>
                  <phase>site</phase>
                  <configuration>
                    <tasks>
                     <copy file="test_resources\jmeter\jakarta-jmeter-2.2\extras\expand.jpg"
toFile="target/site/jmeter-results/expand.jpg"> 
                     </copy>
                     <copy file="test_resources\jmeter\jakarta-jmeter-2.2\extras\collapse.jpg"
toFile="target/site/jmeter-results/collapse.jpg">
                     </copy>
                   </tasks>
            </configuration>
          <goals>
            <goal>run</goal>
          </goals>
         </execution>
       </executions>
   </plugin> 
 


Share.

About Author

Robbrecht is a development manager at AMIS Services. He is Agile coach and Certified Agile Master. He has 10+ years of experience in managing projects with Scrum (first with DSDM). Robbrecht is a strong proponent of the agile principles. With AMIS Robbrecht is responsible for implementing the AMIS Software factory based upon Hudson, Maven, Jira and Subversion and implementing Agile as default method for AMIS projects.

9 Comments

  1. A lot of the problems mentioned in the comments have been fixed in the latest version and this plugin is now under active development again.  It is now available from the central maven repository so you no longer need to specify a repository in your POM to use it, all that is required now is:
     
    <plugin>
    <groupId>com.lazerycode.jmeter</groupId>
    <artifactId>jmeter-maven-plugin</artifactId>
    <version>1.4</version>
    <executions>
    <execution>
    <id>jmeter-tests</id>
    <phase>verify</phase>
    <goals>
    <goal>jmeter</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    Note that the GroupID and ArtifactID have changed.
    Project website is http://jmeter.lazerycode.com

  2. We are having a problem with functions like ${__threadNum}, they are not being replaced when JMeter is executed by the Maven plugin. Has anybody experienced the same? Any ideas what might be causing this? No problems when running the script with the JMeter GUI or command-line. I did find the following messages in the logging:

    2007/10/03 15:55:49 DEBUG – jmeter.testelement.property.AbstractProperty: Not running version, return raw function string
    2007/10/03 15:55:49 DEBUG – jmeter.engine.util.ValueReplacer: Replacement result: test${__threadNum}

  3. Well, I finally found out the way to do this. Is not nice but it works.

    I had to modify the Maven JMeter Plugin to add all the needed classes to the ClassLoader that JMeter uses.
    This is achieved reading a text file with all the dependencies of the project (generated previously with the maven-dependency-plugin).

    I’m waiting that Tim McCune confirm me that he accepts my modification to update his plugin.

  4. Robbrecht van Amerongen on

    I have no experience with JunitSampler option within Jmeter. This features is introduced in version 2.1.2.
    I think you have to add the test.jar as an dependency within your pom. I have not tried this yet.
    The HTTPSampler does not give these problems.

  5. Hi Bobbrecht, I have deployed jmeter-2.2.jar in a internal repository. The log says that it couldn’t find my test classes.
    What do you mean with JMeter helper classes?
    I have all the dependencies that JMeter needs

    I have this line in my target/jmeter/jmeter.log file:

    2007/08/13 11:06:38 WARN – jmeter.protocol.java.sampler.JUnitSampler: ClassNotFoundException:: com.foo.TestClass

    Can you tell me which version of Java are you using?
    Maybe there is a problem with classpath.

    Thanks

  6. Robbrecht van Amerongen on

    Lean,
    The whole Jmeter process is run in maven. It seems that the ClassNotFoundException has to do with something in your JMeter Test.
    You should add additional helper class files from JMeter as an dependency in your pom.xml.

    I hope this will solve your problem.

  7. Haven’t you got a ClassNotFoundException in the jmeter/jmeter.log file after running it?
    If you did, how did you solve it?

    Thanks.