tags:

views:

16

answers:

1

I have a bean in which I've injected an HttpServletRequest using the @Autowired annotation.

This injection works correctly when the application context is a web application Context. That's not the case for application contexts for JUnit tests with Spring.

How can I test this bean ? Maybe I can mock an http request, but then how to inject this mock in the bean ?

This is on Spring 3.0 and Junit 4.4

+3  A: 

Create a bean of type MockHttpServletRequest and add it to your test context. This should then be autowired into your target bean.

skaffman