I am trying to run a JUnit test using JMeter 2.7. However, when you select test classes in the drop-down patch of the JUnit sampler, they do not appear. As I found out, this is because test classes extend from another class ( AbstractJUnit4SpringContextTests
is a base class with various abstract classes in between, providing convenient methods) for all tests. You can select a test class that does not extend from these base classes.
A JAR file containing test classes is created by Maven (test-jar), a JAR containing all dependencies is created by the maven fatjar plugin. Both banks are placed in the JMeter / lib / junit directory.
I know that the JMeter manual says that all test classes should extend to the JUnit test class, but this is similar to JUnit3. With JUnit4, JMeter does not need this requirement. Of course, I could rewrite all the tests so that they could not extend from the base class, but this can lead to a huge maintenance problem. So, how do I run JUnit tests with JMeter that extend from the base class?
UDPATE 2012-08-09
Thanks to the PMD hint, I now copied the dependencies one by one into the JMeter lib folder, and now the GUI displays all my unit tests. Before this was possible, I had to solve a couple of problems:
- Copying logkit-1.0.1.jar to a folder prevented the JMeter GUI from starting. I donβt know why, there were no error messages or logs. The JVM has just begun and ended.
- There were some version conflicts caused by maven dependencies that introduced older versions of spring test packages. This has led some test classes to extend from an older base class with the same name. Excluding these dependencies in the pom file helped.
Now I can run my JUnit test cases. However, several links in my classes are annotated with @Resource
. The JMeter tester does not seem to inject these links, because every time it accesses the link, a NullPointerException
, as can be seen from the JMeter log. So, how can I get JMeter to inject these dependencies, is this possible?
source share