Dependency Injection should make your code less dependent on the container than it would be with traditional Java EE development.The POJOs that make up your application should be testable in JUnit or TestNG tests, with objects simply instantiated using the new operator, without Spring or any othercontainer.You can use mock objects (in conjunction with other valuable testing techniques) to test your code in isolation.If you follow the architecture recommendations for Spring, the resulting clean layering and componentization of your codebase will facilitate easier unit testing.For example, you can test service layer objects by stubbing or mocking DAO or Repository interfaces, without needing to access persistent data while running unit tests.
True unit tests typically run extremely quickly, as there is no run time infra structure to set up. Emphasizing true unit tests as part of your development methodology will boost your productivity.You may not need this to help you write effective unit tests for your IoC-based applications. For certain unit testing scenarios, however, the Spring Frame work provides the following mock objects and testing support classes.
The org. spring frame work. mock. jndi package contains an implementation of the JNDI SPI, which you can use to set up a simple JNDI environment for test suites or stand-alone applications. If, for example, JDBC Data Sources get bound to the same JNDI names in test code as within a Java EE container, you can reuse both application code and configuration in testing scenarios without modification.
The org. spring frame work. mock. web package contains a comprehensive set of Servlet API mock objects, targeted at usage with Spring's Web MVC framework, which are useful for testing web contexts and controllers. These mock objects are generally more convenient to use than dynamic mock objects such as EasyMock or existing Servlet API mock objects such as MockObjects.
The org. spring frame work. mock. web. portlet package contains a set of Portlet API mock objects, targeted at usage with Spring's Portlet MVC framework.
Unit testing support classes
The org. spring frame work. test.util package contains Reflection Test Utils, which is a collection of reflection-based utility methods. Developers use these methods in unit and integration testing scenarios in which they need to set a non-public field or invoke a non-public setter method when testing application code involving, for example:
The org. spring frame work. test. web package contains Model And View Assert, which you can use in combination with JUnit 4+, TestNG, and so on for unit tests dealing with Spring MVC Model And View objects.
Unit testing Spring MVC Controllers
To test your Spring MVC Controllers, use Model And View Assert combined with Mock HttpS ervlet Request, Mock Http Session, and so on from the org.spring frame work .mock.web package.
Java-Springs Related Interview Questions
|Adv Java Interview Questions||J2EE Interview Questions|
|Core Java Interview Questions||JSP Interview Questions|
|Java-Springs Interview Questions||Java Servlets Interview Questions|
|JMS(Java Message Service) Interview Questions||Hibernate Interview Questions|
|Java applet Interview Questions||Java Interview Questions|
|Framework7 Interview Questions||Java collections framework Interview Questions|
|Java 8 Interview Questions||Java Programmer Interview Questions|
Introduction To Spring Framework
New Features And Enhancements In Spring 3.0
The Ioc Container
Validation, Data Binding, And Type Conversion
Spring Expression Language (spel)
Aspect Oriented Programming With Spring
Spring Aop Apis
Data Access With Jdbc
Object Relational Mapping (orm) Data Access
Marshalling Xml Using O/x Mappers
Web Mvc Framework
Integrating With Other Web Frameworks
Portlet Mvc Framework
Remoting And Web Services Using Spring
Enterprise Javabeans (ejb) Integration
Jms (java Message Service)
Task Execution And Scheduling
Dynamic Language Support
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.