接口性能测试--JMeter(2)

发表于:2015-04-20来源:uml.org.cn作者:不详点击数: 标签:性能测试
3)GetPersonTest为某一类具有相似业务场景的测试类 其中 getDefaultParameters方法设置默认参数:test传入具体要执行的 测试方法 ;info传入日志级别,利用main方法

  3)GetPersonTest为某一类具有相似业务场景的测试类

  其中 getDefaultParameters方法设置默认参数:test传入具体要执行的测试方法;info传入日志级别,利用main方法进行调试时设置为true,真正进行性能测试的时候设置为false

package  com . xxx . yyy . perf;
import  org.apache.jmeter.config.Argument;
import  org.apache.jmeter.config.Arguments;
import  org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import  org.apache.jmeter.samplers.SampleResult;
import  org.springframework.context.ApplicationContext;
import  org.springframework.context.support.ClassPathXmlApplicationContext;
import  com.xxx.udb.client.PersonService;
import  com.xxx.udb.client.result.MultiPersonResult;
import  com.xxx.udb.client.result.PersonResult;
import  com.xxx.udb.perf.base.AbstractServiceClient;
/**
* Test get person
* @author flynewton
*/
public  class  GetPersonTest  extends  AbstractServiceClient  {
private  static  final  ApplicationContext  ctx  =  new ClassPathXmlApplicationContext(
"spring-udb.xml");
private  static  PersonService  personService  =  null;
private  static  String  loginIdCache  =  "00000sb";
private  static  String  loginIdWithoutCache  =  "01haytham";
private  static  String  siteIdCache  =  "CN";
private  static  String  siteIdWithoutCache  =  "IN";
private  static  String  alimailCn  =  "gchg2008@zzgcchen.cn";
private  static  String  alimailUdb  =  "000001@lvcuinm.com.cn";
private  static  String  uidCache  =  "300113578";
private  static  String  uidWithoutCache  =  "in5002997";
private  static  String  emailCache  =  "00000sb@alibaba-test.com";
private  static  String  emailWithoutCache  =  "5002997@alibaba-inc.com";
@Override
public  void  setupTest( JavaSamplerContext  context)  {
super . setupTest( context);
personService  = ( PersonService)  ctx . getBean( "personServiceClient");
}
public  Arguments  getDefaultParameters()  {
Arguments  params  =  new  Arguments();
params . addArgument( "test" ,  "testMethod");
params . addArgument( "info" ,  "false");
return  params;
}
@Override
public  void  teardownTest( JavaSamplerContext  context)  {
super . teardownTest( context);
}
public  Object  testGetPersonByLongIdViaCache( JavaSamplerContext  arg0 ,
SampleResult  sample)  {
PersonResult  personResult  =  null;
try  {
sample . sampleStart();
personResult  =  personService . getPersonByLongId( siteIdCache , loginIdCache);
sample . sampleEnd();
}  catch ( Throwable  t)  {
this . getLogger (). error( "Exception:"  +  t);
return  null;
}
return  personResult;
}
public  Object  testGetPersonByLongIdWithoutCache( JavaSamplerContext  arg0 ,
SampleResult  sample)  {
PersonResult  personResult  =  null;
try  {
sample . sampleStart();
personResult  =  personService . getPersonByLongId( siteIdWithoutCache , loginIdWithoutCache);
sample . sampleEnd();
}  catch ( Throwable  t)  {
this . getLogger (). error( "Exception:"  +  t);
return  null;
}
return  personResult;
}
public  Object  testGetPersonByAlimailCN( JavaSamplerContext  arg0 ,
SampleResult  sample)  {
PersonResult  personResult  =  null;
try  {
sample . sampleStart();

原文转自:http://www.uml.org.cn/Test/201401163.asp