Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Deploying JMeter and Ant on Ubuntu for Continuous Integration

Tech 3

To set up JMeter and Ant for automated enterface testing in a Jenkins container, follow these steps to install and configure the necessary components on Ubuntu.

Installing JDK on Ubuntu

  1. Download the JDK package, such as jdk-8u74-linux-x64.tar.gz, and transfer it to the server using lrzsz. Install lrzsz with sudo apt-get install lrzsz. Use rz to upload files from your local machine to the server and sz to download files from the server.

  2. Extract the JDK archive. Run tar -xvf jdk-8u74-linux-x64.tar.gz to create a directroy like jdk1.8.0_74.

  3. Configure environment variables. Edit /etc/profile with vi and add:

    export JAVA_HOME=/usr/local/java/jdk1.8.0_74
    export PATH=$JAVA_HOME/bin:$PATH
    

    Apply the changes with source /etc/profile.

  4. Verify the installation by running java -version.

Installing JMeter

  1. Package the local JMeter files into a ZIP archive, such as apache-jmeter-3.2.zip, and upload it to the server using rz.

  2. Install unzip if not present: apt-get install unzip.

  3. Extract the archive with unzip apache-jmeter-3.2.zip, resulting in a directory like apache-jmeter-3.2.

  4. Move the extracted directory to /usr/local.

  5. Set JMeter environment variables. Edit /etc/profile and add:

    export JMETER=/usr/local/apache-jmeter-3.2
    export PATH=$JMETER/bin:$PATH
    

    Execute source /etc/profile to activate.

  6. Check the setup by running jmeter -v.

Testing JMeter Scripts

Run a JMeter script in non-GUI mode with:

jmeter -n -t /tmp/apache-jmeter-3.2/bin/lsmsp.jmx -l log.jtl

Parameters:

  • -n: Run without GUI
  • -t: Specify the script file
  • -l: Define the output log file

View results with cat log.jtl.

Enstalling Ant on Ubuntu

  1. Install Apache Ant, such as apache-ant-1.9.9, in /usr/local using a similar method as JMeter.

  2. Configure Ant environment variables. Edit /etc/profile and append:

    export ANT_HOME=/usr/local/apache-ant-1.9.9
    export PATH=$ANT_HOME/bin:$PATH
    

    Apply with source /etc/profile and verify with ant -v.

  3. Copy ant-jmeter-1.1.3.jar from jmeter/extras to ant/lib.

Configuring build.xml for Ant

Create a build.xml file to automate JMeter test execution with Ant. Two approaches are outlined below.

Option 1: Direct Script Execution This method runs scripts stored locally in the JMeter directory.

<?xml version="1.0" encoding="UTF-8"?>
<project name="jmeter-ant-run" default="execute" basedir=".">
    <tstamp>
        <format property="timestamp" pattern="yyyyMMddHHmm" />
    </tstamp>
    <property environment="sysenv"/>
    <property name="reportTitle" value="PerformanceTest" />
    <property name="jmeter.install" value="/usr/local/apache-jmeter-3.2" />
    <property name="jmeter.result.jtl" value="${sysenv.WORKSPACE}/output/${sysenv.BUILD_ID}/${sysenv.BUILD_ID}.jtl" />
    <property name="jmeter.result.html" value="${sysenv.WORKSPACE}/output/${sysenv.BUILD_ID}/${sysenv.BUILD_ID}.html" />
    <target name="execute">
        <echo message="Initiating test..."/>
        <antcall target="setup" />
        <antcall target="runTests" />
        <antcall target="generateReport" />
    </target>
    <target name="setup">
        <mkdir dir="${sysenv.WORKSPACE}/output/${sysenv.BUILD_ID}" />
    </target>
    <target name="runTests">
        <taskdef name="jmeterTask" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
        <jmeterTask jmeterhome="${jmeter.install}" resultlog="${jmeter.result.jtl}">
            <testplans dir="/usr/local/apache-jmeter-3.2/bin/testScripts" includes="sample.jmx" />
            <property name="jmeter.save.saveservice.output_format" value="xml"/>
        </jmeterTask>
    </target>
    <target name="generateReport">
        <xslt in="${jmeter.result.jtl}"
              out="${jmeter.result.html}"
              style="${jmeter.install}/extras/jmeter-results-detail-report_21.xsl" />
    </target>
</project>

Option 2: Git-Based Script Retrieval This approach fetches scripts from a Git repository before execution.

<?xml version="1.0" encoding="UTF-8"?>
<project name="jmeter-git-ant" default="launch" basedir=".">
    <tstamp>
        <format property="currentTime" pattern="yyyyMMddHHmm" />
    </tstamp>
    <property environment="envVars"/>
    <property name="reportName" value="TestSummary" />
    <property name="jmeter.path" value="/usr/local/apache-jmeter-3.2" />
    <property name="result.dir" value="/usr/local/apache-jmeter-3.2/results/${envVars.BUILD_ID}" />
    <property name="result.jtl" value="${result.dir}/${reportName}.jtl" />
    <property name="result.html" value="${result.dir}/${reportName}.html" />
    <property name="git.local" value="${envVars.WORKSPACE}" />
    <target name="launch">
        <echo message="Starting process..."/>
        <antcall target="prepare" />
        <antcall target="executeTests" />
        <antcall target="createReport" />
    </target>
    <target name="prepare">
        <mkdir dir="${envVars.WORKSPACE}/results/${envVars.BUILD_ID}" />
    </target>
    <target name="executeTests">
        <taskdef name="jmeterExec" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
        <jmeterExec jmeterhome="${jmeter.path}" resultlog="${result.jtl}">
            <testplans dir="${git.local}" includes="demo.jmx" />
            <property name="jmeter.save.saveservice.output_format" value="xml"/>
        </jmeterExec>
    </target>
    <path id="xslt.classpath">
        <fileset dir="${jmeter.path}/lib" includes="xalan*.jar"/>
        <fileset dir="${jmeter.path}/lib" includes="serializer*.jar"/>
    </path>
    <target name="createReport">
        <tstamp>
            <format property="reportDate" pattern="yyyy/MM/dd HH:mm" />
        </tstamp>
        <xslt classpathref="xslt.classpath"
              force="true"
              in="${result.jtl}"
              out="${result.html}"
              style="${jmeter.path}/extras/jmeter.results.shanhe.me.xsl">
            <param name="dateReport" expression="${reportDate}"/>
        </xslt>
        <copy todir="${result.dir}">
            <fileset dir="${jmeter.path}/extras">
                <include name="collapse.png" />
                <include name="expand.png" />
            </fileset>
        </copy>
    </target>
</project>

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.