General |
|
Main |
|
Develop |
Kotlin DSL
plugins {
id("de.qualersoft.jmeter") version "<latest>"
}
Groovy DSL
plugins {
id 'de.qualersoft.jmeter' version '<latest>'
}
The easiest way to customize the plugin is via its jmeter
extension.
The extension offers the following properties
jmeter {
systemPropertyFiles // (1)
systemProperties // (2)
mainPropertyFile // (3)
additionalPropertyFiles // (4)
jmeterProperties // (5)
customReportTemplate // (6)
globalPropertiesFile // (7)
globalProperties // (8)
proxxScheme // (9)
proxyHost // (10)
proxyPort // (11)
nonProxyHosts // (12)
logConfig // (13)
logOutputFile // (14)
jmxRootDir // (15)
resultDir // (16)
reportDir // (17)
maxHeap // (18)
jvmArgs //(19)
enableRemoteExecution // (20)
exitRemoteServers // (21)
}
Details
-
Additional system property file(s).
-
Define additional system properties.
-
The jmeter property file to use.
-
Additional JMeter property file(s).
-
Define additional JMeter properties.
-
Path to a custom report-template folder used by report generator.
-
Path to a JMeter property file which will be sent to all servers.
-
Properties which will be sent to remote servers.
-
Scheme of the proxy (e.g. for non-http).
-
Proxy server hostname or ip address.
-
Proxy server port.
-
Non-proxy hosts (e.g *.apache.org).
-
Custom log configuration file (currently log4j2)
Defaults to bundled configuration. -
File where jmeter log will be written to.
Defaults to <buildDir>/logs/jmeter.log -
Used to search for jmx files.
Defaults to src/test/jmeter -
Directory to which the jtl-files will be written.
Defaults to <buildDir>/test-results/jmeter -
Root directory where to put the reports
Defaults to <buildDir>/reports/jmeter -
[Optional] Specifies the maximum heap size the JVM process will start with.
-
[Optional] additional JVM arguments that will be passed to the jvm directly.
-
[Optional] tells JMeter™ to run the tests on the configured remote-servers (see remoting)
Defaults tofalse
. -
[Optional] Flag to exit remote servers at the end of the test. Only effective iff
enableRemoteExecution
istrue
.
Defaults tofalse
.
These configurations will be applied to all tasks (where appropriate) and can be overridden or extended on a per task base.
❗
|
Important
To use the quickstarter you must have gradle installed and available on your path
|
-
In a folder of your choice (referred to as
root
), execute:root> gradle init --dsl kotlin --type basic
This brings up the setup. We are going to create a
basic
project and usingKotlin
as build script DSL. -
Create the following folder structure (gradle stuff from 1. left out)
root ├── src │ └── test │ └── jmeter │ └── Test.jmx (1) └── build.gradle.kts (2)
-
default folder for jmx-files is
src/test/jmeter
You can copy theTest.jmx
from functional test resources -
build.gradle.kts is generated by gradle; we need it in next step.
-
-
Put the following into
build.gradle.kts
import de.qualersoft.jmeter.gradleplugin.task.* // (1) plugins { id("de.qualersoft.jmeter") version "<latest>" // (2) } repositories { mavenCentral() // (3) } tasks { register<JMeterRunTask>("runJMeter") { // (4) jmxFile.set("Test.jmx") // (5) } }
-
Import
task
package. (to save some typing later on 😋) -
Apply the plugin. (Don’t forget to correct the version 😉)
-
We need a repository to retrieve jmeter-library.
mavenCentral
should work in almost any case. -
Register a run-task and give it a name (if we wouldn’t had imported the
task
package in (1), we would have to use the full qualified path) -
Configure the task to use our test.jmx file under
src/test/jmeter
-
-
Run it by opening a cli of your choice in
root
root> ./gradlew runJMeter
Output... Starting standalone test @ Sat Sep 04 18:53:51 CEST 2021 (1630774431340) Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445 Warning: Nashorn engine is planned to be removed from a future JDK release summary = 30 in 00:00:03 = 10,0/s Avg: 206 Min: 108 Max: 345 Err: 2 (6,67%) Tidying up ... @ Sat Sep 04 18:53:55 CEST 2021 (1630774435185) ... end of run BUILD SUCCESSFUL in 15s 1 actionable task: 1 executed
👏 Congratulations, you’ve run your first jmeter script with this plugin.
🎉 4 steps, that’s it. Simple, wasn’t it?
After you’ve run your first jmeter script successfully, you might want to have a report showing some nice charts and stats.
No problem, just:
-
add the following to your
build.gradel.kts
stask
sectiontasks { register<JMeterRunTask>("runJMeter") { jmxFile.set("Test.jmx") } register<JMeterReportTask>("jmeterReport") { // (1) jmxFile.set("Test.jmx") // (2) } }
-
registering a
JMeterReportTask
task (remember the include? Now it pays off 😊) -
by pointing it to our
jmx
file the plugin knows where to find everything
-
-
back in CLI run
root> ./gradlew jmeterReport
This generates the report under
build/reports/jmeter/Test
ℹ️NoteThe directory 'Test' is retrieved from the jmx-file’s name.
🎉 Voila, just 2 steps to get a report.
Remark that to generate a report, you have to execute the runJMeter
task before. There are two ways you can get it in one rush.
-
Declare a
dependsOn
in report taskregister<JMeterReportTask>("jmeterReport") { jmxFile.set("Test.jmx") dependsOn("runJMeter") }
if you now execute
jmeterReport
,runJMeter
get executed first if required -
Or let the 'run' task always generate a report with
generateReport
flagregister<JMeterRunTask>("runTest") { jmxFile.set("Test.jmx") generateReport = true }
💡TipIf you are going to rerun the task without cleaning outputs you will get an error because the report already exists. In such cases just enable thedeleteResults
property
No problem, just add the following task to your build-script
tasks {
register<JMeterGuiTask>("edit") {
jmxFile.set("Test.jmx")
}
}
And back to CLI
root> ./gradlew edit
As an alternative, if you don’t want to clutter your tasks-section, you can use the jmeter
-extension
jmeter {
withGuiTask("edit") {
jmxFile.set("Test.jmx")
}
}
All tasks also provide some of their properties through cli-arguments.
To see what arguments are supported by a task simply run
root> ./gradlew help --task <taskName> (1)
-
with <taskName> being a JMeter*Task defined in your build script. E.g. our 'runTest' task from above.
As mentioned in the preamble, this plugin is designed to be as flexible as possible.
By that, the used jmeter runner artifact as well as plugins or libraries aren’t hardwired but can be configured.
You can easily configure not only the version but also its coordinates. All this can be done through the jmeter.tool
property.
jmeter {
tool {
group // (1)
name // (2)
version // (3)
mainConfigureClosure // (4)
mainClass // (5)
}
}
Details
-
The group-id of the jmeter-runner.
Defaults to 'org.apache.jmeter'. -
The name (artifact-id) of the jmeter-runner.
Defaults to 'ApacheJMeter'. -
the version of the jmeter-runner.
Defaults to '5.5'. -
A closure/lambda to configure the dependency any further.
Will only applied if notnull
(which is the default). -
The main class used to execute the jmeter runner.
Defaults to 'org.apache.jmeter.NewDriver'.
Because the runner itself is quite useless without any plugins you can add them with the jmeterPlugin
dependency handler
dependencies {
jmeterPlugin("org.jmeter:a-plugin:1.2.3") // (1)
}
-
Resolves the 'a-plugin' and puts its artifact into
/lib/ext
, transitive dependencies will be put tolib
directory.
ℹ️
|
Please note the Pitfalls when using jmeter-dependencies/-plugins section. |
By default, this plugin includes the following plugins (as they are also default plugins in a normal JMeter installation):
"bolt", "components", "core", "ftp", "functions", "http", "java", "jdbc", "jms", "junit", "ldap", "mail", "mongodb", "native", "tcp"
Info
At the current time, these plugins are hardwired and cannot be modified.
(Yeah, I know, so much about flexibility… Mea culpa! 😉)
Sometimes you have quite special and reusable code that you wouldn’t maintain within JMeter. Or you just want to use an existing libraries functions within JMeter.
To make them available to JMeter you can use the jmeterLibrary
dependency handler
dependencies {
jmeterLibrary("org.apache.commons:commons-csv:1.9.0") // (1)
}
-
Resolves the 'commons-csv' artifact and puts its artifact, and all its transitive dependencies, under
/lib
directory.
ℹ️
|
Please note the Pitfalls when using jmeter-dependencies/-plugins section. |
🔥
|
Internal only
Within an IDE with autocomplete, you may also notice the |
Some of the jmeter dependencies or plugins, which you want to apply through jmeterLibrary
or jmeterPlugin
might
depend on 'org.apache.jmeter:bom'.
This dependency seems not available on any maven-repository (for further information refer to Issue 64465).
If you are affected by this issue, you will see an error message similar to
... > Could not resolve all dependencies for configuration ':jmeterPlugin'. > Could not find org.apache.jmeter:bom:5.5. Required by: project > ...
when executing one of the jmeter-tasks.
As a convenient workaround, the jmeter-gradle-plugin
provides the jmeter.tool.applyBomWorkaround
function.
You can apply it to the affected dependencies like this:
dependencies {
// in case a library is affected
jmeterLibrary("org.apache.jmeter:a-library:1.2.3") {
jmeter.tool.applyBomWorkaround(this)
}
// or in case a plugin is affected
jmeterPlugin("org.jmeter:a-plugin:1.2.3") {
jmeter.tool.applyBomWorkaround(this)
}
}