weixin_40098530
weixin_40098530
采纳率100%
2018-05-04 08:27 阅读 3.9k
已采纳

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

20

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    durie_ durie_ 2018-05-05 02:58
     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实例

    点赞 评论 复制链接分享
  • dabocaiqq dabocaiqq 2018-05-04 10:32

相关推荐