Jmeter:将jmeter Junit请求与变量一起使用 [英] Jmeter: Using jmeter Junit Request with variables

查看:257
本文介绍了Jmeter:将jmeter Junit请求与变量一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我在问题中所说的,是否可以将jmeter变量(通过-J传递)到JUnit Request,以便可以在内部将其用于junit测试?

As I said in the question, is it possible to pass jmeter variables (passed through -J) into a JUnit Request in order that it can be used internally to the junit test?

Apache Junit Request文档指出:

... JMeter当前直接运行测试方法,而不是 留给JUnit. ...

... JMeter currently runs the test methods directly, rather than leaving it to JUnit. ...

这表明jmeter可以控制传递参数,但是我没有找到任何支持文档,而且通过JUnit Request采样器配置没有明显的机制.

This would indicate that jmeter could control passing parameters but I've found no supporting documentation and there's no obvious mechanism through the JUnit Request sampler config.

背景

我希望使用CSV Data Set Config加载用户池(如

I was hoping to use CSV Data Set Config to load a user pool (as in Victor Klepikovskiy excellent top tips) and have a randomly obtained user provided to my unit-tests (for use across the thread/ loop). I've found an alternative way of doing what I want (but use my own user pool accessed from within the junit tests). I know you could manage the login through Http Request too (as above) but we amanage the rest-service calls internally to junit so that they can be run as junit tests as well. I was interested in being as non-intrusive as possible.

这样做的第二个原因可能是只有一个junit测试方法,但要对其进行参数设置以适合这种情况.

A second reason for doing so might be to have a single junit test method but have it parameterised to suit the scenario.

附录

对于它的价值,我对当前的替代方法感到满意,但仍对您如何能够这样做以供将来参考感兴趣.我对jmeter相当陌生,但希望能看到更多.也正在考虑查看预处理器,但不确定这些预处理器如何与Junit Request交互.

For what it's worth, I'm happy with my current alternative approach but still interested in how you might be able to do this for future reference. I'm fairly new to jmeter but expect to see a fair bit more of it. Was also thinking of looking at the pre-processors but not sure how these could interface with the Junit Request.

推荐答案

我已经测试过,并且一切正常.需要做的是: 资料来源:blazemeter.com how-use-junit-jmeter

I tested and it all works. what needs to be done is: Source: blazemeter.com how-use-junit-jmeter

1)在项目库中添加以下jar文件:

1) add the following jar files in the project libraries:

.. \ JMeter \ apache-jmeter-3.0 \ lib \ ext \ ApacheJMeter_core.jar

..\JMeter\apache-jmeter-3.0\lib\ext\ApacheJMeter_core.jar

.. \ JMeter \ apache-jmeter-3.0 \ lib \ ext \ ApacheJMeter_junit.jar

..\JMeter\apache-jmeter-3.0\lib\ext\ApacheJMeter_junit.jar

2)在类中,将引用添加到采样器:

2) in the class, add the reference to the sampler:

导入org.apache.jmeter.protocol.java.sampler.JUnitSampler;

import org.apache.jmeter.protocol.java.sampler.JUnitSampler;

3)在@Test标记中添加代码以处理变量: 单击以查看代码

3) Add the code in the @Test tag to handle variables: Click to see Code

4)在JMeter中定义变量(在用户中定义变量和CSV)

4) Define variables in JMeter (both in user define variables and CSV)

单击以查看JMeter Config

希望有帮助!

这篇关于Jmeter:将jmeter Junit请求与变量一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆