JMeter基于Cucumber执行JUnit测试(Java)

huangapple 未分类评论55阅读模式
英文:

JMeter to execute JUnit tests based on Cucumber (java)

问题

我是自动化测试的初学者。

我正试图执行用Java编写的、基于Selenium WebDriver、带有Cucumber和Gherkin注释的测试,这些测试在JMeter中运行。

当我在没有JMeter的情况下运行我的测试时,我只是利用机会使用运行器类(在Eclipse中)将它们作为JUnit测试运行。

要在JMeter中运行我的测试,我创建了一个jar文件,上传到JUnit子文件夹,所有依赖的jar文件都上传到了lib子文件夹。

我尝试在JMeter中创建一个JUnit请求,但没有帮助,因为在使用Cucumber时,我们不会使用@Test标记方法。我只为我的运行器类有一个空构造函数(如上图所示)。

我试着将我的jar添加到测试计划并在BeanShell中创建一个类的实例,但它不会被执行为JUnit测试。

我的问题是如何运行基于Selenium WebDriver的基于Cucumber和Gherkin的Java测试脚本?

也许我必须使用其他采样器...

非常感谢任何示例。

英文:

I am a beginner at automation testing.

I am trying to execute tests that were written in java using Selenium WebDriver, Cucumber with Gherkin annotations in JMeter.

When I run my tests without JMeter, I just use the opportunity to run them as Junit test using the runner class (in Eclipse).

JMeter基于Cucumber执行JUnit测试(Java)

To run my tests in JMeter, I created a jar file, uploaded it to Junit sub-folder, all dependencies-jars were uploaded to lib sub-folder.

I tried to create a JUnit request in JMeter, but it didn't help as when we use Cucumber, we don't mark methods with @Test. I have just an empty constructor for my Runner class (as you can see from the picture above).

I tried to add my jar to Test Plan and create an instance of my class in BeanShell, but it is not executed as JUnit tests.

JMeter基于Cucumber执行JUnit测试(Java)

JMeter基于Cucumber执行JUnit测试(Java)

My question is how to run java test scripts that were written based on Cucumber with Gherkin (based on Selenium WebDriver)?

Maybe I have to use other Samplers...

Any examples are greatly appreciated.

答案1

得分: 0

我相信你需要运行另一个类,特别是 io.cucumber.core.cli.Main,类似于:

  1. io.cucumber.core.cli.Main.main(new String[]{
  2. "—glue",
  3. "包含glue类的包名",
  4. "/你的/特性/文件路径"});

详细的可用参数说明,请参阅 Running Cucumber -> 从命令行。顺便说一句,你可以使用 OS Process Sampler 来实现这一点,会更容易。


根据你想要实现的目标,将你的 Selenium 测试转换为“本地”的 JMeter 测试可能更快、更容易,因为如果你要使用 Selenium 测试来创建负载,将需要巨大的硬件资源,并且你无法获得 HTTP 协议级别的性能指标。

英文:

I believe you need to run another class, in particular io.cucumber.core.cli.Main, something like:

  1. io.cucumber.core.cli.Main.main(new String[]{
  2. "--glue",
  3. "the package which contains the glue classes",
  4. "/your/feature/file"});

Check out Running Cucumber -> From the command line for all the available arguments explained. By the way, you can use OS Process Sampler for this, it will be way easier.


Depending on what you're trying to achieve it might be faster and easier to convert your Selenium tests into "native" JMeter ones as if you're going to use your Selenium tests for creating the load it will require immense hardware resources and you won't get performance metrics on the HTTP protocol level.

huangapple
  • 本文由 发表于 2020年6月29日 11:48:53
  • 转载请务必保留本文链接:https://java.coder-hub.com/62630910.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定