通过java 程序调用jmeter 实现自动测试

各位大神:
谁有这样的demo提供一个 我参考一下 。脚本是否可以通过页面传递的参数自动生成
执行脚本的方式?

2个回答

 public class AutoNumberRmiTest extends AbstractJavaSamplerClient
{
    private AutoNumberSeqService autoNumberSeqService;
    private TenantParam tenantParam;



    @Override
    public Arguments getDefaultParameters() {
        Arguments args = new Arguments();
        args.addArgument("label","用户接口测试");
        args.addArgument("hostAddress","");
        args.addArgument("tenantId","");
        args.addArgument("itemId","");
        return args;
    }




    @Override
    public void setupTest(JavaSamplerContext context) {
        try {
            autoNumberSeqService = (AutoNumberSeqService) Naming.lookup("//"+context.getParameter("hostAddress")+":9238/AutoNumberSeqRMIService");
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (NotBoundException e) {
            e.printStackTrace();
        }
        tenantParam = new TenantParam(context.getLongParameter("tenantId"));
        super.setupTest(context);
    }




    public SampleResult runTest(JavaSamplerContext javaSamplerContext) {
        long itemId = javaSamplerContext.getLongParameter("itemId");
        SampleResult sampleResult = new SampleResult();
        sampleResult.setSampleLabel(javaSamplerContext.getParameter("label"));

        sampleResult.setSuccessful(false);
        try {
            sampleResult.sampleStart();
            String autoNuberCode = autoNumberSeqService.buildCodeByItem(itemId, tenantParam);
            if (autoNuberCode != null) {
                sampleResult.setSuccessful(true);
                sampleResult.setResponseData(autoNuberCode);  
                sampleResult.setDataType(SampleResult.TEXT);  
            }

        }  catch (CustomizeException e) {
            e.printStackTrace();
            sampleResult.setSuccessful(false);
        } finally{
            sampleResult.sampleEnd();
        }
        return sampleResult;
    }



}

这是之前我写的一个用例,参考 JMeter入门:04Java Request实例

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问