Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit test classes not showing up in JMeter

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?

like image 530
Jim Holden Avatar asked Jul 27 '12 11:07

Jim Holden


People also ask

Can JMeter be used for unit testing?

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.

What JUnit is in BlueJ?

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.


2 Answers

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.

like image 155
UBIK LOAD PACK Avatar answered Oct 18 '22 23:10

UBIK LOAD PACK


Did you check the option that JUnit sampler has to search for v4 tests?

JMeter option to search for JUnit 4 annotations

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.

like image 21
Nacho Cougil Avatar answered Oct 19 '22 01:10

Nacho Cougil