簡體   English   中英

獲取jmeter功能測試代碼覆蓋率

[英]Get jmeter functional test code coverage

我正在嘗試使用maven插件提取有關jmeter功能測試執行的代碼覆蓋率報告。 我嘗試使用jacoco插件對其進行配置,以生成代碼覆蓋率報告,但是它似乎只能使用Java類格式(例如* IT.java或* Test.java)進行的單元測試和集成測試進行配置。 但是在我的情況下,使用Jmeter插件對Jmeter .jmx文件進行了功能測試。 我知道獲得功能測試的代碼覆蓋率很少見,但是如果有人從事過類似的工作,請分享一些細節。 以下是我用於Jmeter測試執行的插件。

<plugin>
               <groupId>com.lazerycode.jmeter</groupId>
                   <artifactId>jmeter-maven-plugin</artifactId>
                   <version>2.1.0</version> 
                   <executions>
                     <execution>
                              <id>jmeter-tests</id>
                              <phase>verify</phase>
                              <goals>
                                <goal>jmeter</goal>
                              </goals>
                         </execution>
                  </executions> 
                  <configuration>
                    <ignoreResultFailures>true</ignoreResultFailures>
                    <resultsDirectory>${jmeter-testresults}</resultsDirectory>
                        <propertiesUser> 
                              <hostname>${jmeter-testhost}</hostname>
                              <hostport>${jmeter-testport}</hostport>
                              <testresults>${jmeter-testresults}</testresults>
                    </propertiesUser> 
                       <propertiesJMeter>
                              <jmeter.save.saveservice.url>true</jmeter.save.saveservice.url>
                              <jmeter.save.saveservice.samplerData>true</jmeter.save.saveservice.samplerData>
                       </propertiesJMeter> 
              </configuration>
            </plugin>

我能夠使用git bash命令行獲取代碼覆蓋率。 以下是步驟。

  • http://www.eclemma.org/jacoco/下載jacoco項目,然后在本地下載,例如C:/ jacoco。 它在lib文件夾中將包含jacocoagent.jar和jacococli.jar。

  • 打開Git bash(您也可以使用簡單的命令行)。

    出口MAVEN_OPTS =“-javaagent:C:\\ jacoco \\ lib \\ jacocoagent.jar = output = tcpserver”
    mvn exec:java -Dexec.mainClass =“主程序包的完整名稱”

上面的命令將在服務器啟動期間將jacocoagent注入到maven jvm中,以便它可以讀取和捕獲執行流並將其存儲在tcpserver上。 我使用tcpserver作為輸出,通過使用文件模式,我需要適當地關閉jvm以獲得執行數據。 服務器啟動后,執行

mvn驗證

驗證命令與我的pom xml中的Jmeter執行插件集成在一起。 因此,verify命令將觸發我的Jmeter測試執行。 現在,由於執行數據位於tcp服務器上,因此我們需要將其轉儲到jacoco文件中以獲取報告。 執行以下命令以將執行數據轉儲到jacoco.exec文件中

java -jar C:/jacoco/lib/jacococli.jar dump --destfile“您的本地路徑/jacoco.exec”

現在,您應該在提到的路徑中看到一個jacoco.exec文件。 但是,此數據不是人類可讀格式。 要生成可讀的html格式的報告,請執行以下命令。

java -jar C:/jacoco/lib/jacococli.jar報告“ jacoco文件/jacoco.exec的路徑” --classfiles“項目類文件的路徑” --html“存儲report \\ jacoco-report的路徑” --name myReport --sourcefiles“到源文件的路徑”

現在您應該能夠看到在給定路徑下生成的html格式的報告。

參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM