TA的每日心情 | 难过 2015-12-2 11:05 |
---|
签到天数: 7 天 连续签到: 2 天 [LV.3]测试连长
|
初学,照着网上抄了个例子:
服务类:
package com.test.webservice;
public class Hello {
public int sum(int a, int b){
return a + b;
}
}
测试类:
package com.test.webservice;
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 PerfTest extends AbstractJavaSamplerClient {
private String a;
private String b;
private String resultData;
// 这个方法是用来自定义java方法入参的。
// params.addArgument("num1","");表示入参名字叫num1,默认值为空。
//设置可用参数及的默认值;
//已设置的参数会显示到Jmeter的参数列表中
public Arguments getDefaultParameters(){
Arguments params = new Arguments();
params.addArgument("num1","");
params.addArgument("num2","");
return params;
}
//每个线程测试前执行一次,做一些初始化工作;
public void setupTest(JavaSamplerContext arg0) {
}
//开始测试,从arg0参数可以获得参数值;
public SampleResult runTest(JavaSamplerContext arg0){
a = arg0.getParameter("num1");
b = arg0.getParameter("num2");
SampleResult sr = new SampleResult();
sr.setSampleLabel("Java请求测试!");
try{
sr.sampleStart();
Hello test = new Hello();
resultData = String.valueOf(test.sum(Integer.parseInt(a), Integer.parseInt(b)));
if(resultData != null && resultData.length() > 0){
sr.setResponseData("结果是:" + resultData, null);
sr.setDataType(SampleResult.TEXT);
}
System.out.println(resultData);
sr.setSuccessful(true);
}catch (Throwable e){
sr.setSuccessful(false);
e.printStackTrace();
}finally{
sr.sampleEnd();
}
return sr;
}
//测试结束时调用;
public void teardownTest(JavaSamplerContext arg0) {
// System.out.println(end);
// System.out.println("The cost is"+(end-start)/1000);
}
// main只是为了调试用,最后打jar包的时候注释掉。
public static void main(String[] args)
{ // TODO Auto-generated method stub
Arguments params = new Arguments();
params.addArgument("num1", "1");//设置参数,并赋予默认值1
params.addArgument("num2", "2");//设置参数,并赋予默认值2
JavaSamplerContext arg0 = new JavaSamplerContext(params);
PerfTest test = new PerfTest();
test.setupTest(arg0);
test.runTest(arg0);
test.teardownTest(arg0);
}
}
当运行main方法进行调试时报错,报错如下:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/jorphan/logging/LoggingManager
at org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient.<clinit>(AbstractJavaSamplerClient.java:55)
Caused by: java.lang.ClassNotFoundException: org.apache.jorphan.logging.LoggingManager
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
请问为啥在eclipse里面不能用main方法进行调试呢?是要导入什么包吗??代码并没有报错呀。
|
|