0

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

1 Answer 1

5
  1. No, you cannot have two @RunWith, instead you should use other ways that Mockito provides to create a Mock stand-in.

  2. The way to specify multiple locations is this:

    @ContextConfiguration(locations={"first.xml", "second.xml"})
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.