I have a session scoped bean which holds user data per http session. I would like to write a Junit test case to test the session scoped bean. I would like to write the test case such that it can prove that the beans are getting created per session. Any pointer as how to write such Junit test case?
相关问题
- java.lang.IllegalArgumentException: Cannot set to
- Spring Data MongoDB - lazy access to some fields
- Dependencies while implementing Mocking in Junit4
- Declaring an explict object dependency in Spring
- Decoding body parameters with Spring
相关文章
- java JDK动态代理和cglib动态代理最后获取的代理对象都为null的问题
- org.xml.sax.SAXParseException; lineNumber: 7; colu
- spring-mvc a标签带参怎样向controller发送请求。路径格式?
- SpringMVC如何把File封装到Map中?
- Spring: controller inheritance using @Controller a
- How to load @Configuration classes from separate J
- Java spring framework - how to set content type?
- Java/Spring MVC: provide request context to child
In order to use request and session scopes in unit test you need to:
RequestContextHolder
Something like this (assume that you use Spring TestContext to run your tests):
abstractSessionTest.xml
:.
Now you can use these methods in your test code:
I came across this simpler approach, thought I might as well post here in case others need it.
With this approach, you don't have to mock any request/session objects.
Source: http://tarunsapra.wordpress.com/2011/06/28/junit-spring-session-and-request-scope-beans/
Spring 3.2 and newer provides support for session/request scoped beans for integration testing
References: