-
Notifications
You must be signed in to change notification settings - Fork 0
badrishdavey/common-spring-mvc-testing-framework
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This repository contains spring based framework which can be commonly used among different spring mvc applications (especially for JSP View based apps). Features: - No need to learn new APIs or guide. Ready to use framework. - Custom View Resolver has been included in framework which will be used to hack rendering of JSP pages (which require server deployment). - This framework is a Plug/Play framework which requires minimal configuration. - This framework must only be used for Integration testing. Include this project as JAR in your project (Scope: TEST only). - This framwork can be used for end to end integration testing. In turn, it can increase the code coverage unexpectedly. Thus, it will be ideal if you don't include mvc integration testing in your code coverage. - Work is still in progress becuase rendering of JSP pages without Server deployment is not feasible. I will keep working on finding some alternative and update this framework. How to use it: MAVEN: - Update your pom.xml with following snippet: <dependency> <groupId>common.mvc.integration-test</groupId> <artifactId>common-mvc-integration-testing</artifactId> <version>1.0.0-SNAPSHOT</version> <scope>test</scope> </dependency> - Checkout this project and deploy the distribution in your internal repository. (with same version that you mentioned above) - Enhance your Integration Test Suite using below sample as base: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations="classpath:test-servlet.xml", loader=MockWebApplicationContextLoader.class) @MockWebApplication(name="Any-controller", webapp="/webapp") public class AnyControllerTest extends AbstractControllerTestSupport{ // Your test code here. @Test public void viewTest() throws ServletException, IOException { MockHttpServletRequest request = new MockHttpServletRequest("GET", "ANY_URL"); MockHttpServletResponse response = new MockHttpServletResponse(); getServletInstance().service(request, response); String results = response.getContentAsString().trim(); // Your testing code here } } More updates will be coming soon... Testing a spring controller method having @ModelAttribute as parameter: ** Pick the html element names and fill the paramter values in MockHttpRequest object and pass it over. Set the values in the request as parameters following the OGNL paths matching the model attribute/form paths. ------------------------------------------------------------ Example: MockHttpServletRequest httpServletRequest = MockRequestResponseGenerator.mockRequest(getServletInstance().getServletContext(), "POST", "/test", paramters); //These paramters must be part of the ModelAttribute Object. Make sure, you are using custom property binding in case you have different object. httpServletRequest.setParameter("name", "SPRING MVC INTEGRATION TEST TEMP"); httpServletRequest.setParameter("id", "1"); httpServletRequest.setParameter("desc", "SPRING MVC INTEGRATION TEST DESC"); getServletInstance().service(httpServletRequest, httpServletResponse); --------------------------------------------------------------------- Thanks to Tejus and Ted Young for head start on spring mvc integration testing. For other views (like freemarker and XML/Json) which don't depend on server deployment, please refer to: https://github.com/SpringSource/spring-test-mvc framework.
About
This project will provide common framework to do integration testing on spring mvc based apps without deploying on any server.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published