Jmeter:使用带有变量的 jmeter Junit 请求 [英] Jmeter: Using jmeter Junit Request with variables

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

问题描述

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

这听起来是可行的,因为 Apache Junit 请求文档 表明:><块引用>

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

这表明 jmeter 可以控制传递参数,但我没有找到支持文档,也没有通过 JUnit 请求采样器配置的明显机制.

背景

我希望使用 CSV 数据集配置 来加载用户池(如 Victor Klepikovskiy 优秀的顶级技巧)并随机获得一个用户提供给我的单元测试(用于跨线程/循环).我找到了一种替代方法来做我想做的事(但使用我自己的从 junit 测试中访问的用户池).我知道您也可以通过 Http Request 管理登录(如上所述),但我们在内部管理对 junit 的其余服务调用,以便它们也可以作为 junit 测试运行.我有兴趣尽可能不打扰别人.

这样做的第二个原因可能是只有一个 junit 测试方法,但对其进行参数化以适应场景.

附录

就其价值而言,我对我目前的替代方法感到满意,但仍然对您如何能够做到这一点感兴趣以供将来参考.我对 jmeter 相当陌生,但希望能看到更多.也在考虑查看预处理器,但不确定它们如何与 Junit 请求交互.

解决方案

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

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

..JMeterapache-jmeter-3.0libextApacheJMeter_core.jar

..JMeterapache-jmeter-3.0libextApacheJMeter_junit.jar

2) 在类中,添加对采样器的引用:

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

3) 在@Test标签中添加处理变量的代码:点击查看代码

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

点击查看JMeter配置

希望能帮到你!

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?

It sounds feasible as the Apache Junit Request docs indicate that:

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

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.

Background

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.

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

Addendum

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.

解决方案

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

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

..JMeterapache-jmeter-3.0libextApacheJMeter_core.jar

..JMeterapache-jmeter-3.0libextApacheJMeter_junit.jar

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

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

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

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

Click to see JMeter Config

Hope it helps!

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

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