File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Spring3 MVC junit testing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Spring3 MVC junit testing" Watch "Spring3 MVC junit testing" New topic

Spring3 MVC junit testing

Amitosh Mishra
Ranch Hand

Joined: Feb 11, 2010
Posts: 49
Hi All,

I am trying to learn junit testing for spring controller.

find below the test Class i have written

in newUsewr2 method I'm trying to access the request parametre like

but i'm getting Null Pointer exception while accesing Request object.

please provide help to access request object in this scenario

i don't want to pass request object in newUser2 method.

Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
I don't see any variable named request being defined in newUser2(). You will have to have a static reference variable of request then.
Amitosh Mishra
Ranch Hand

Joined: Feb 11, 2010
Posts: 49
i want to access servletrequest object in non dispatcher servlet environment.
is there any way to this except passing request object as parameter??
Amitosh Mishra
Ranch Hand

Joined: Feb 11, 2010
Posts: 49
Hi ,
I resolved this by setting

in my test method
and accessing request as

in controller class method.
I agree. Here's the link:
subject: Spring3 MVC junit testing
Similar Threads
Integration testing of Spring 2.5 Annotation based controller using web context
Error Reading data from database
EasyMockClassExtension not mocking class
Testing Spring Controller
Scope Request