Problem passing parameters from Gradle to JMeter


(Eugene Dvorkin) #1

I am working on setting up JMeter test running from Gradle. I want to override request.threads count property as well as loop property as described in Ant Task for JMeter: You can override JMeter properties (instead of modifying jmeter.properties) like this:

<jmeter
    jmeterhome="c:\jakarta-jmeter-1.8.1"
    testplan="${basedir}/loadtests/JMeterLoadTest.jmx"
    resultlog="${basedir}/loadtests/JMeterResults.jtl">
 <property name="request.threads" value="1"/>
 <property name="request.loop" value="10"/>
</jmeter>

Here is my gradle script:

task JMeter << {
  ant.taskdef( name:"jmeter",classname:"org.programmerplanet.ant.taskdefs.jmeter.JMeterTask") {
   classpath { fileset(dir: "$projectDir/tools/apache-jmeter-2.7/lib", includes: 'ant-jmeter-1.1.1.jar')
  }
  }
     ant.jmeter(jmeterhome:"$projectDir/tools/apache-jmeter-2.7",
     resultlog:"${buildDir}/test-results/JMeterResults-10-users.jtl")
            {
     testplans(includes:"*.jmx",dir:"$projectDir/src/test/resources/load")
     jvmarg(value: "-Xms512m")
     property(name:'request.threads',value:10)
     property(name:'request.loop',value:20)
                                  }
          ant.jmeter(jmeterhome:"$projectDir/tools/apache-jmeter-2.7",
     resultlog:"${buildDir}/test-results/JMeterResults-20-users.jtl")
            {
     testplans(includes:"*.jmx",dir:"$projectDir/src/test/resources/load")
     jvmarg(value: "-Xms512m")
     property(name:'request.threads',value:20)
     property(name:'request.loop',value:20)
                                  }
    ant.jmeter(jmeterhome:"$projectDir/tools/apache-jmeter-2.7",
     resultlog:"${buildDir}/test-results/JMeterResults-50-users.jtl")
            {
     testplans(includes:"*.jmx",dir:"$projectDir/src/test/resources/load")
     jvmarg(value: "-Xms512m")
     property(name:'request.threads',value:50)
     property(name:'request.loop',value:20)
                                  }
             }

Debug message from gradle execution:

The ' characters around the executable and arguments are
not part of the command.
10:14:25.020 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Execute:Java13CommandLauncher: Executing 'C:\Program Files\Java\jdk1.7.0_04\jre\bin\java.exe' with arguments:
'-Xms512m'
'-jar'
'C:\Users\edvorkin\Documents\workspace\CommunicationsPlatform\tools\apache-jmeter-2.7\bin\ApacheJMeter.jar'
'-n'
'-t'
'C:\Users\edvorkin\Documents\workspace\CommunicationsPlatform\src\test\resources\load\CPRestAPI.jmx'
'-l'
'C:\Users\edvorkin\Documents\workspace\CommunicationsPlatform\build\test-results\JMeterResults-50-users.jtl'
'-Jrequest.threads=50'
'-Jrequest.loop=20'

Problem is my result still have only default number of thread, in my case 10. It just ignores the line

property(name:‘request.threads’,value:50).

Is there something with my build script or it is JMeter issue? Anybody did this from gradle?

Thanks in advance


(kellyrob) #2

Best guess is that there is a scoping problem with the ant dsl, and that once the property is set, the default ant behaviour is to ignore any subsequent sets. This code demonstrates how you can use a different syntax to override the value, if this is actually what’s happening:

task antTest <<{
    ant.property(name:'message', value:5)
    ant.property(name:'message', value:50)
    println ant.properties.message
    ant.properties['message'] = 50
    println ant.properties.message
}

The second call to ant.property is ignored, but the value can be changed by accessing the properties map directly. Hope this helps.