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

查看:142
本文介绍了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插件创建.这两个罐子都放在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中的一个文件,然后在每个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 .

在lib文件夹中一个一个地添加所有jar.

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天全站免登陆