@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-config/ui-test-config.xml")
public class MyParticularTest {
@Autowired
private Controller controller;
...
}
This is really nice, but... there is one thing we stumbled upon lately.
The test framework by default is using the GenericXmlContextLoader
which loads the Spring application context as an instance of GenericApplicationContext
. This class, obviously, is not aware of web applications that would require a WebApplicationContext
instead. Hence, you can't access any web related resources, use associated scopes etc.
Don't get me wrong... Spring TestContext Framework is nice, but it's more than strange that it does not support the web scenario. There is a Jira issue for that, but it's still open for more than 10 months now, and is scheduled not until Spring 3.1?!? That's just annoying.
Well, there are some workarounds of course, based on using a custom context loader. See this blog post or this Spring community thread, for instance.
No comments:
Post a Comment