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:
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?
This JMeter and JUnit integration help in load testing of customized Java methods – the JUnit tests. Integrating JUnit in JMeter helps in finding the time taken by individual tests with the applied load using various JMeter capabilities.
JUnit is a regression testing framework written by Erich Gamma and Kent Beck. You can find the software and a lot of information about it at http://www.junit.org . The systematic testing tools in BlueJ are based on JUnit.
You must put your junit classes in lib/junit folder as you did and dependencies in lib folder.
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 .
Add all your jars one by one in lib folder.
Check jmeter logs to see if you have any exception .
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.
Did you check the option that JUnit sampler has to search for v4 tests?
I've tried and this works for a simple project I've created with JUnit 4, it filters only tests with the @Test annotations even those classes doesn't extend TestCase class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With