标签:style blog http java color 使用
getDefaultParameters() 用于获取界面的参数 |
|
runTest(JavaSamplerContext context)
类似于LR的Action |
|
void |
setupTest(JavaSamplerContext context) 初始化方法,类似于LR的init和Junit中的setUp() |
void |
teardownTest(JavaSamplerContext context) 类似于LR的end和Junit中的tearDown() |
package com.test.jmeter; import java.io.IOException; import org.apache.http.client.ClientProtocolException; 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; public class Jmeter_GetSearchSuggestion extends AbstractJavaSamplerClient { private static String label = "Jmeter_GetSearchSuggestion "; //定义label名称,显示在jmeter的结果窗口 private String url; private String data; public void setupTest(){ //定义测试初始值,setupTest只在测试开始前使用 System.out.println("setupTest"); } @Override public SampleResult runTest(JavaSamplerContext arg0) { url = arg0.getParameter("url"); data = arg0.getParameter("data"); SampleResult sr; sr = new SampleResult(); sr.setSampleLabel(label); TestApiGetSearchSuggestion t = new TestApiGetSearchSuggestion(); sr.sampleStart(); try { //调用被压测接口的方法 t.PostJson(url, data); sr.setSuccessful(true); } catch (ClientProtocolException e) { sr.setSuccessful(false); e.printStackTrace(); } catch (IOException e) { sr.setSuccessful(false); e.printStackTrace(); } sr.sampleEnd(); // jmeter 结束统计响应时间标记 return sr; } public void teardownTest(JavaSamplerContext arg0){ super.teardownTest(arg0); } public Arguments getDefaultParameters(){ //参数定义,显示在前台,也可以不定义 Arguments params = new Arguments(); params.addArgument("url", "http://gapp.test.com/merchandise/GetSearchSuggestion"); params.addArgument("data", "data={\"token\": \"aaaaaaaaaa\",\"body\": {\"keywords\": \"蓝月亮\"}}"); return params; } }
标签:style blog http java color 使用
原文地址:http://blog.csdn.net/kash_chen007/article/details/37690411