I've seen the link Spring Test session scope bean using Junit that shows how to setup Junit to test @Session scoped beans, but how do I set up a Junit test case to test a Spring bean that has a @Session scoped bean @Autowired into it.
Asked
Active
Viewed 1,946 times
2
-
Solution from this link works with your case too. – MariuszS Jan 30 '14 at 13:37
1 Answers
1
If you're testing the behaviour of the spring bean, the easiest way to do this is to mock the object and inject it yourself using ReflectionTestUtils:
class SpringBean {
@Autowired Other other;
public void method() {
// ...
}
}
class SpringBeanTest {
@Test public void testIt() {
Other other = new Other();
SpringBean bean = new SpringBean();
ReflectionTestUtils.setField(bean, "other", other);
// test it
}
}

Matthew Farwell
- 60,889
- 18
- 128
- 171