JUnit 测试类未显示在 JMeter 中 [英] JUnit test classes not showing up in JMeter

查看:20
本文介绍了JUnit 测试类未显示在 JMeter 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 JMeter 2.7 运行 JUnit 测试.但是,在 JUnit 采样器的下拉列表中选择测试类时,它们不会显示.正如我发现的那样,这是因为测试类是从另一个类(AbstractJUnit4SpringContextTests 是基类,中间有各种抽象类提供便利方法)扩展而来的.可以选择不是从这些基类扩展的测试类.

I'm trying to run JUnit test with JMeter 2.7. However, when selecting the test classes in the drop down of the JUnit sampler, they don't show up. As I found out, that's because the test classes are extending from another class (AbstractJUnit4SpringContextTests is the base class, with various abstract classes inbetween providing convenience methods) for all tests. A test class that is not extended from those base classes can be selected.

包含测试类的 JAR 文件由 Maven (test-jar) 创建,包含所有依赖项的 JAR 由 maven fatjar 插件创建.两个jar包都放在JMeter/lib/junit目录下.

The JAR file containing the test classes is created by Maven (test-jar), the JAR containing all dependencies is created by the maven fatjar plugin. Both jars are placed in the JMeter/lib/junit directory.

我知道 JMeter 手册说所有测试类都必须从 JUnit 测试类扩展,但这似乎只适用于 JUnit3.使用 JUnit4,JMeter 不需要该要求.当然,我可以重写所有测试,这样它们就不必从基类扩展,但这会导致巨大的维护问题.那么,如何使用从基类扩展而来的 JMeter 执行 JUnit 测试?

I know that the JMeter manual says that all test classes must extend from the JUnit test class, but that only seems to be true for JUnit3. With JUnit4, JMeter does not need that requirement. Of course, I could rewrite all test so that they don't have to extend from the base class, but that would result a huge maintenance issue. So, how do I execute JUnit tests with JMeter that extend from a base class?

UDPATE 2012-08-09

多亏了PMD的提示,我现在把依赖项一一复制到JMeter的lib文件夹下,现在GUI显示了我所有的单元测试.在这成为可能之前,我必须自己解决几个问题:

Thanks to the hint of PMD, I now copied the dependencies one by one to the lib folder of JMeter, and now the GUI shows all my unit tests. Before that was possible, I had to solve a couple of problems by myself:

  • 将 logkit-1.0.1.jar 复制到文件夹中会阻止 JMeter GUI 启动.不知道为什么,没有给出错误或日志消息.JVM 刚刚启动和终止.
  • maven 依赖引入了旧版本的 spring 测试包导致了一些版本冲突.这导致一些测试类从具有相同名称的旧基类扩展而来.在 pom 文件中排除这些依赖项会有所帮助.

我现在可以执行我的 JUnit 测试用例了.但是,我的类中的几个引用都使用 @Resource 进行了注释.JMeter 的 Testrunner 似乎没有注入这些引用,因为每次访问引用时,都会抛出一个 NullPointerException,如 JMeter 日志中所示.那么,我如何让 JMeter 注入这些依赖项,这可能吗?

I can now execute my JUnit test cases. However, several references in my classes are annotated with @Resource. The Testrunner of JMeter doesn't seem to inject those references, because every time a reference is accessed, a NullPointerException is thrown, as can be seen in the JMeter log. So, how I do I get JMeter to inject those dependencies, is that even possible?

推荐答案

您必须将您的 junit 类放在 lib/junit 文件夹中,并将依赖项放在 lib 文件夹中.

You must put your junit classes in lib/junit folder as you did and dependencies in lib folder.

您不应该使用 fatjar,因为有时这些工具会从 meta-inf 中删除文件,或者只从所有 jar 中保留一个,spring pûts 在每个 jar 中都有一个.

You shouldn't use fatjar as sometimes these tools removed files from meta-inf or only keep one from all jars, spring pûts one in each of its jars .

将你所有的jar一一添加到lib文件夹中.

Add all your jars one by one in lib folder.

检查 jmeter 日志,看看是否有任何异常.

Check jmeter logs to see if you have any exception .

如果仍然失败,请在 jmeter 用户列表上提问,如果没有得到任何答案,请创建一个简单的测试用例并打开一个错误.

If it still fails, ask a question on jmeter user list and if you don't get any answer create a simple test case and open a bug.

这篇关于JUnit 测试类未显示在 JMeter 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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