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.
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.
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
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:
- Copying the logkit-1.0.1.jar into the folder prevented the JMeter GUI from starting. No idea why, no error or log message was given. The JVM just started and terminated.
- The were some version conflicts caused by maven dependencies which introduced older versions of the spring test packages. That resulted in some test classes extending from an older base class with the same name. Excluding those dependencies in the pom file helped.
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?