JUnit test classes not showing up in JMeter

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?

+6
source share
4 answers

You must put your junit classes in the lib / junit folder, as you did, and the dependencies in the lib folder.

You should not use fatjar, because sometimes these tools delete files from meta-inf or just save one of all the jars, spring pΓ»ts one in each of its jars.

Add all your banks one by one to the lib folder.

Check the jmeter logs to see if you have any exceptions.

If it still does not work, ask a question about the jmeter user list, and if you do not get an answer, create a simple test case and open an error.

+4
source

Have you checked that JUnit sampler should look for v4 tests?

JMeter option to search for JUnit 4 annotations

I tried and it works for a simple project that I created using JUnit 4, it only filters tests with @Test annotations, even these classes do not extend the TestCase class.

+2
source

In Jmeter 4.0, instead of putting dependencies in the JMeter lib folder, you can specify the path to the dependency locations through the user.classpath property. This property is located in the "user.properties" file in the / bin folder of your JMeter installation.

The path element may be a JAR file or directory. Any jar file in such a directory will be automatically included, jar files in subdirectories are ignored.

When adding paths, pay attention and use the path separator of your platform (java.io.File.separatorChar in Java) to separate multiple paths:

 #Example for windows (; separator) #user.classpath=../classes;../lib;../app1/jar1.jar;../app2/jar2.jar #Example for linux (:separator) #user.classpath=../classes:../lib:../app1/jar1.jar:../app2/jar2.jar user.classpath=C:/git/adf-bpm-autotesting-tool/libs;C:/git/adf-bpm-autotesting-tool/libs/selenium-tools;C:/git/adf-bpm-autotesting-tool/libs/selenium-2.52.0;C:/git/adf-bpm-autotesting-tool/libs/selenium-2.52.0/libs 

As the correct result, when you start jmeter gui, you will see the following entries in the jmeter.log entries:

 2019-04-08 18:51:46,871 INFO oajJMeter: Adding to classpath and loader: C:/git/adf-bpm-autotesting-tool/libs 2019-04-08 18:51:46,872 INFO oajJMeter: Adding to classpath and loader: C:/git/adf-bpm-autotesting-tool/libs/selenium-tools 2019-04-08 18:51:46,873 INFO oajJMeter: Adding to classpath and loader: C:/git/adf-bpm-autotesting-tool/libs/selenium-2.52.0 2019-04-08 18:51:46,873 INFO oajJMeter: Adding to classpath and loader: C:/git/adf-bpm-autotesting-tool/libs/selenium-2.52.0/libs 

After that, in the JUnit Request Sample, you will find all your junit tests.

0
source

As Teinacher wrote, the JUnit test will appear in JMeter after copying all the project dependencies (all .jar files) to the JMeter / lib directory (a restart of JMeter is required).

-1
source

Source: https://habr.com/ru/post/921483/


All Articles