Loading
MockStrutsTestCase Example

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  Unit Testing of Struts Action Class.


Ans)

"Servletunit" should be used to perform the Unit Testing of the Struts actions also as we need ServletRequest/Response etc.,  for this.

 "MockStrutsTestCase" should be used for this purpose. Please see below for full example.

Step 1 :

Please download "servletunit" jar

Step 2:

Your Test Case should extend "MockStrutsTestCase".

Step 3:

Create your TestCase as follows .

public class EditActionTest extends MockStrutsTestCase {
public EditActionTest(String name) {
  super(name);
 }
 public void tearDown() throws Exception {
        closeSession();
 }

   public void test_update() throws Exception{

  addRequestParameter("method", "update");
  addRequestParameter("contactId", "273016914");
  addRequestParameter("reloadContact", "false");
  addRequestParameter("zipCode", "08053");
  addRequestParameter("address1" , new String[]{"225 Test road", "Apt 6","Test City","Test State"});
  
  setRequestPathInfo("/contactDetailsEdit");
  actionPerform();
  verifyForwardPath("/contactDetails.do?contactId=273016914");

  verifyNoActionErrors();
  assertEquals(request.getAttribute("isAddressVarified"), true);

 }

 @Test
 public void test_getContactData() throws Exception {

  ContactForm form = new ContactForm();
  HttpServletRequest request = createMock(HttpServletRequest.class);
 
 BigDecimal oppObjid = new BigDecimal("273028572");

  Contact opportunity = (Contact) ContactServices
    .getOpportunityByObjid(oppObjid);
 }
}



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

MockStrutsTestCase Example


MockStrutsTestCase Example

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free