This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a Maven (v 3.0.3) project using Spring 3.0.5.RELEASE. I want to write a mock Spring JUnittest to verify that one of my controllers is redirecting to the proper view. However, I can't get my application context to load properly. I have these files ...
Then in my Spring JUnit test, I have
However, upon running my JUnit test from Maven, I get the error
What is the proper way to reference my web.xml file? Thanks, - Dave
You don't reference the web.xml. The web.xml file is not a Spring configuration file.
If you want to Unit Test your controller, you don't need to have Spring started up in your test. But you might have to stub or mock out any Web specific classes with something like HttpMock.
Your Controller should be a pojo, so you don't need a true web environment in your tests.
Also, those two files that are in WEB-INF. Well that isn't in your classpath. And you are trying to load them with classpath. However, you can't use http: either, since your tests will not be running in a Web Environment. So you will need to have a different config file in your test directory that is in your classpath.