简体   繁体   中英

JMeter JUnit SpringRunner issue

My JUnit tests were defined like this:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/spring-test.xml" })
public abstract class MyTest {

It works perfectly well when tests are running normally via maven, etc. But, when I tried to run it using JMeter, seems like it is no longer setting spring dependencies defined in the xml file, looks like this RunWith annotaion is ignored. I'm getting NPE when trying to use spring injected deps. Is there a solution how to solve it properly ?

The JUnit Sampler implementation is not using the standard JUnit Runner facility. See point 7 in the documentation ( http://jmeter.apache.org/usermanual/component_reference.html#JUnit_Request ).

Also read the discussion in this ticket: https://issues.apache.org/bugzilla/show_bug.cgi?id=47888#c1 .

If your are interested in the implementation have a look at org.apache.jmeter.protocol.java.sampler.JUnitSampler .

Trying to get the same thing working since a few days.
Problem with annotations though.
It ran in jmeter without using the annotations, like loading the context using:

ApplicationContext context = new FileSystemXmlApplicationContext("Spring-Module.xml");
context.getBean("helloWorld");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM