I wanted to write few unit tests for my application that uses Spring MVC. I read the manual page at the Spring home page:http://static.springsource.org/spring/docs/current/spring-framework-reference/html/testing.html
and it seems that this Spring testing framework could be really useful.
But here are the questions:
1.If I understand it right, to use any of the annotations for testing like @ContextConfiguration
I need to use @RunWith(SpringJUnit4ClassRunner.class)
? But is it possible to use two runners (probably not), I just wondered if one can use Spring runner and mockito one, because I am using mockito to mock normal objects.
2.I have a question about loading xml context files with @ContextConfiguration
. I have my .xml files in src/main/webapp/WEB-INF/spring
, how can I load them using ContextConfiguration
? I tried
@ContextConfiguration(locations="/webapp/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="webapp/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="/src/main/webapp/WEB-INF/spring/root-context.xml")
@ContextConfiguration(locations="src/main/webapp/WEB-INF/spring/root-context.xml")
but I always get class path resource [some_path] cannot be opened because it does not exist
.I am wondering then what path should I use?
EDIT: the second problem was that WEB-INF is not in the classpath, here is the topic that helped me Location of spring-context.xml