JMeter, JUnit and Spring Java configuration

馋奶兔 提交于 2019-12-30 17:24:24

问题


Is it possible to run JMeter with the JUnit plugin/sampler and Spring Java configuration? When I try to do this, the Spring autowired beans are not being created and although the test case runs, because the beans have not been created, I get null pointer exceptions.

I am using the Spring annotation @SpringJUnit4ClassRunner and @ContextConfiguration to configure the JUnit test (which works). The goal is to be able to write JUnit test cases that can be measured for performance using JMeter.


回答1:


Yes, running JMeter with JUnit and Spring is a problem. JMeter does not use standard JUnit runner; its specified at User manual, point 7. There are subtle differences between standard JUnit test runners and JMeter's implementation. Because of this, @SpringJUnit4ClassRunner is becomes ignored. Workaround is to load beans as normal i.e using ApplicationContext.getBean().



来源:https://stackoverflow.com/questions/33748421/jmeter-junit-and-spring-java-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!