Hi,
Exception am getting is [CODE] [junit] java.lang.IllegalStateException: ApplicationObjectSupport instance [com.xyz.erp.web.LoginController@bc0eba] does not run in an ApplicationContext[CODE]
I know there are more threads available on this topic but i am confused and missing something on how to implement the same.
I need to unit test my LoginController when i wrote the below small piece of code and run the test the below exception is coming
I am getting
java.lang.IllegalStateException: ApplicationObjectSupport instance [com.LoginController@16f0472] does not run in an ApplicationContext
Code:
public class LoginControllerTest extends TestCase{
private LoginController loginController;
private AuthenticationService authenticationService;
public void setUp( ) throws Exception { loginController=new LoginController();
authenticationService=EasyMock.createMock(AuthenticationService.class); }
public void testWithoutCredentialsLogin()throws Exception{
MockfromServletRequest req=new MockfromServletRequest();
req.setMethod(quot OSTquot;);
req.addHeader(quot;refererquot;, quot;testquot;);
MockfromServletResponse res=new MockfromServletResponse();
loginController.setAuthenticationService(authenticationService);
ModelAndView mv=loginController.handleRequest(req,res);
assertNotNull(quot;Model And View should not be Nullquot;,mv);
assertEquals(quot;Invalid view namequot;,quot;loginquot;, mv.getViewName());
}
I want to unit test my Controller.
My application has
controller------service------dao layers
how to unittest the above layers individually and by intgration??
Please guide me with some example/link.
Thanks
please guid me in this regard |