Jmeter測試Java請求樣本__Java

來源:互聯網
上載者:User

一、核心步驟
1.建立一個Java工程;

2.將JMeter的lib目錄下的jar檔案添加進此工程的Build Path;
ApacheJMeter_core.jar(必須)、ApacheJMeter_java.jar(必須)、avalon-framework-4.1.4.jar、jorphan.jar、logkit-2.0.jar
後台3個為本地調試需要用到的包檔案

3.建立一個類並實現JavaSamplerClient介面或繼承AbstractJavaSamplerClient,並重寫;

構建待測試類別:

[java]  view plain  copy   public class MathTest {       public String sayHello()       {           return "Hello";       }       public String sayHelloToPerson(String s)       {           if(s == null || s.equals(""))               s = "nobody";           return (new StringBuilder()).append("Hello ").append(s).toString();       }       public int sum(int a,int b)       {           return a+b;       }              public static void main(String args[]){           MathTest math = new MathTest();           System.out.println(math.sum(1, 2));       }   }  

public Arguments getDefaultParameters();設定可用參數及的預設值;
public void setupTest(JavaSamplerContext arg0):每個線程測試前執行一次,做一些初始化工作;
public SampleResult runTest(JavaSamplerContext arg0):開始測試,從arg0參數可以獲得參數值;
public void teardownTest(JavaSamplerContext arg0):測試結束時調用;
[java]  view plain  copy   import org.apache.jmeter.config.Arguments;   import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;   import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;   import org.apache.jmeter.samplers.SampleResult;   import com.huize.common.MathTest;         public class JavaTest extends AbstractJavaSamplerClient {       private MathTest test=null;       private String a;       private String b;       private String resultData;       private static long start = 0;       private static long end = 0;              // 這個方法是用來自訂java方法入參的。       

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.