Windows7 64bit
SUN JDK 1.7 64bit
eclipse v3.7
m2e v1.0.100.20110804-1717
eclipse中外掛maven 3.02 java
注意: 因爲jmeter-maven插件運行時自動會引入jmeter所需的類庫,因此機器上不須要單獨安裝jmeter。 git
<build> ... <plugins> <plugin> <groupId>com.lazerycode.jmeter</groupId> <artifactId>jmeter-maven-plugin</artifactId> <version>1.8.2-SNAPSHOT</version> <configuration> <resultsFileFormat>xml</resultsFileFormat> <ignoreResultFailures>true</ignoreResultFailures> <testResultsTimestamp>false</testResultsTimestamp> </configuration> <executions> <execution> <id>jmeter-tests</id> <phase>verify</phase> <goals> <goal>jmeter</goal> </goals> </execution> </executions> <plugins> ... <build>
若是出現找不到構件(artifact)的狀況,考慮切換一下Maven Repository,最直接的方法是在POM中加入相似以下代碼。 github
<pluginRepositories> <pluginRepository> <id>Codehaus repository</id> <url>http://repository.codehaus.org/</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories>
在Eclipse中Run Configurations -> Maven Build -> new中Goals輸入框填入 verify,肯定。 apache
筆者在運行過程曾遇到異常 eclipse
[ERROR] Failed to execute goal com.lazerycode.jmeter:jmeter-maven-plugin:1.8.1:jmeter (jmeter-tests) on project mytodo: Execution jmeter-tests of goal com.lazerycode.jmeter:jmeter-maven-plugin:1.8.1:jmeter failed. NullPointerException -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.lazerycode.jmeter:jmeter-maven-plugin:1.8.1:jmeter (jmeter-tests) on project mytodo: Execution jmeter-tests of goal com.lazerycode.jmeter:jmeter-maven-plugin:1.8.1:jmeter failed. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) Caused by: org.apache.maven.plugin.PluginExecutionException: Execution jmeter-tests of goal com.lazerycode.jmeter:jmeter-maven-plugin:1.8.1:jmeter failed. at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:116) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ... 19 more Caused by: java.lang.NullPointerException at com.lazerycode.jmeter.JMeterAbstractMojo.setJMeterResultFileFormat(JMeterAbstractMojo.java:382) at com.lazerycode.jmeter.JMeterMojo.execute(JMeterMojo.java:43) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107) ... 20 more
查找資料未解決後,找到com.lazerycode.jmeter.JMeterAbstractMojo類第382行中,setJMeterResultFileFormat中對應的代碼: maven
protected void setJMeterResultFileFormat() { if (resultsFileFormat.toLowerCase().equals("csv")) { propertiesJMeter.put("jmeter.save.saveservice.output_format", "csv"); resultsOutputIsCSVFormat = true; } else { propertiesJMeter.put("jmeter.save.saveservice.output_format", "xml"); resultsOutputIsCSVFormat = false; } }
判定是propertiesJMeter爲null所致,爲何這個對象沒初始化,答案目前不得而知。因而去github把jmeter-maven插件最新代碼clone到本地,使用new初始化propertiesJMeter對象,在eclipse中從新打包,獲得jmeter-maven-plugin-1.8.2-SNAPSHOT.jar,再把POM.xml中jmeter-maven-plugin插件版本從1.8.1更換爲1.8.2-SNAPSHOT,再次運行mvn verify ,就看到打印出Build Success字樣。 性能
更多jmeter-maven插件幫助:https://github.com/Ronnie76er/jmeter-maven-plugin/wiki 測試
說明:Performance report是指展示的報告種類,目前支持JMeter和JUnit
若是指定爲JMeter須要指出JMeter測試結果集目錄,**表明pom.xml所在目錄
Performance threshold是指標記本次構建爲Unstable和Failed時所需的最低測試錯誤百分比 ui
注意事項:若是JMeter性能測試比較耗時,就不能把它放在這裏執行,由於它會致使Jenkins構建時間過長。對此,可提早手工使用命令執行,例如:
url
$ jmeter -n -p user.properties -t my_test_plan.jmx -l my_results.jtl
也可把它作成Linux Crontab腳本。還有一種方式是,利用Jenkins的週期性構建功能,勾選Build periodically複選框,設定一個定時執行間隔。