Wednesday, July 31, 2013

JMeter Maven Tutorial (version 1.8.1)



When I stared configuration maven for a project, I didn’t know how to configuration for pom.xml.
 You can read document in link: https://github.com/Ronnie76er/jmeter-maven-plugin.
I think it’s good for you when you make pom.xml file.
I have some problems in configuration maven for my project. Source JMeter in a disk and source Project is other disk.
But the first you must to download [jmeter-maven-plugin-1.8.1.jar] put it in to: ..\extras.
You can execute following steps as below:
1.       Create pom.xml in link: D:\apache-jmeter\jmeter\maven
(to create maven folder inside folder jmeter).
Because Author was configuration workDir in source code JMeter as below:
/**
         * Generate the directory tree utilised by JMeter.
         */
        @SuppressWarnings("ResultOfMethodCallIgnored")
        protected void generateJMeterDirectoryTree() {
               logsDir = new File(workDir, "logs");
               logsDir.mkdirs();
               binDir = new File(workDir, "bin");
               binDir.mkdirs();
               resultsDir = new File(workDir, "results");
               resultsDir.mkdirs();
               libDir = new File(workDir, "lib");
               libExtDir = new File(libDir, "ext");
               libExtDir.mkdirs();
 
               //JMeter expects a <workdir>/lib/junit directory and complains if it can't find it.
               new File(libDir, "junit").mkdirs();


2.       You can copy your project into base.dir.
Example: conf folder (content yourproject.properties, some CSV file,…), results folder (export html file, CSV file, jtl file), scripts folder (main key to run script .jmx file).




3.       You declares properties in pom.xml as below



<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>
                <!--Parent pom.xml-->
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>jmeter-demo</name>
 

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <skipTests>false</skipTests>
<jmeter-version>2.9</jmeter-version>
<jmeter.home>D:/apache-jmeter</jmeter.home>
<jmeter.testfiles.basedir>D:/apachejmeter/jmeter/scripts</jmeter.testfiles.basedir>
                               
</properties>


(You can change {base.dir}, or {user.dir} if you want to change it)

4.       You can config for <propertiesUser> such as:
<propertiesUser>
                                                                                <log_level.jmeter.junit>INFO</log_level.jmeter.junit>
                                                                                                                                <log_level.jmeter.control>DEBUG</log_level.jmeter.control>
                                                                                                                                <log_level.jmeter.testbeans>DEBUG</log_level.jmeter.testbeans>
</propertiesUser>

5.       Main Configuration in pom.xml

<configuration>
                                                                                                               
<skipTests>${skipTests}</skipTests>
<!--Test File Included-->
<testFilesIncluded>
<jMeterTestFile>file.jmx</jMeterTestFile>

</testFilesIncluded>
<!--Test File Excluded-->
<testFilesExcluded>
<excludeJMeterTestFile>File_Document_Search.jmx</excludeJMeterTestFile>
</testFilesExcluded>

<!--File Properties-->
<customPropertiesFile>D:/apache-jmeter/jmeter/conf/Coconet_jmeter.properties</customPropertiesFile>
</configuration>

6.       Plugin to run script
<Plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>1.8.1</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
              </executions>
              </Plugin>

7.       Some Dependencies in pom.xml
<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>2.0b4</version>
</dependency>

<dependency>
<groupId>jcharts</groupId>
<artifactId>jcharts</artifactId>
<version>0.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_report</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_http</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.1.0</version>
</dependency>

<dependency>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-analysis-maven-plugin</artifactId>
<version>1.0.2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>

8.       Run the test
mvn install (mvn verify)

9.       If you want to display the result, I think you should be configuration in pom.xml to follow some steps :
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-analysis-maven-plugin</artifactId>
<version>1.0.2</version>
<executions>
<execution>
<id>jmeter-reports</id>
<phase>report</phase>
<goals>
<goal>analyze</goal>
</goals>
</execution>
               </executions>

<configuration>

<source>D:/apache-jmeter/jmeter/results/**/*.jtl</source>
<targetDirectory>D:/apache-jmeter/jmeter/results</targetDirectory>
<!--
If set to true, additional files "<category>-sizes.csv" and "<category>-durations.csv" will be stored.
These files contain detailed information for response size and response durations for every URI.

Default: true
-->
<generateCSVs>true</generateCSVs>
<generateCharts>true</generateCharts>
<preserveDirectories>false</preserveDirectories>
<suppressJMeterOutput>true</suppressJMeterOutput>
<ignoreResultFailures>true</ignoreResultFailures>
<testResultsTimestamp>true</testResultsTimestamp>
              <appendResultsTimestamp>true</appendResultsTimestamp>
              <processAllFilesFound>true</processAllFilesFound>
</configuration>

10.   Run the result
mvn com.lazerycode.jmeter:jmeter-analysis-maven-plugin:1.0.2:analyze



11.       Some images for results




HoaLe