使用性能測試工具JMeter系列2-運行JUnit Request測試Java API

<!-- /* Font Definitions */ @font-face {font-family:宋體; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋體"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋體; mso-font-kerning:1.0pt;} a:link, span.MsoHyperlink {color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline; text-underline:single;} p {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋體; mso-bidi-font-family:宋體;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

核桃博客 轉載,http://www.hetaoblog.com/?p=56

使用性能測試工具JMeter系列2-運行JUnit Request測試Java API

之前在使用性能測試工具JMeter來測試網站性能1 介紹了使用JMeter的基本使用方式和用來測試網站性能的過程,這裏介紹通過使用JMeter的JUnit Request來做Java API的併發性能測試;

在JMeter 2.1.2後,JMeter增加了JUnit Sampler的功能;這樣,JMeter就可以調用用JUnit寫的Test Case了,通過訪問JUnit的測試代碼,間接完成對Java API的性能測試(事實上,JMeter也支持直接對Java API測試,不過貌似沒有對JUnit的測試來的方便)。下面是主要步驟:

1.     將自己的JUnit測試項目打包成一個完整的Jar,放到JMeter的lib/junit目錄下

2.     建立如下圖所示測試計劃,在JMeter中建立JUnit Request和一種查看結果的方式(比如這裏的表格查看結果的方式後),

其中,JUnit Request的頁面上,可以選擇要測試的類,這裏的com.hetaoblog.api.test.APIManagerTest就是我自己放在lib/junit目錄下的jar包中的測試代碼,在下面還可以選擇要測試的函數和其他參數

  1. 設置好測試計劃後,就想做普通的JMeter測試一樣,點擊運行->啓動,然後再點擊用表格查看結果,就可以看到類似下面的結果:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章