Home Struts Struts Struts2.2.1 Databaseapps Running and testing application

Ask Questions?

View Latest Questions


 
 

Running and testing application
Posted on: February 17, 2011 at 12:00 AM
Advertisement
In this tutorial you will learn how to make a database driven application is struts

Running And Testing Application

The complete database driven application with testing is given below

You can test your application many way like using Mock Object or by using JUnit Framework. I have used Junit to test Action class.

To test you application using JUnit you need to extend the TestCase class of Junit and then write the test case. To know more about the action testing click on the Here.

Here a simple test is done for the execute method of StudenAdmission class. Consider the example

AdmissionActionTest.java

package net.roseindia.test;

import junit.framework.TestCase;
import net.roseindia.action.AdmissionAction;

import com.opensymphony.xwork2.ActionSupport;

public class AdmissionActionTest extends TestCase {

	String result;
	AdmissionAction addmission = new AdmissionAction();

	@Override
	protected void setUp() throws Exception {
		// TODO Auto-generated method stub
		super.setUp();
	}

	public void testExecute() {
		try {
			result = addmission.execute();
		} catch (Exception e) {
			System.out.println("Error Message " + e.getMessage());
		}
		assertEquals(ActionSupport.INPUT, result);
	}

	@Override
	protected void tearDown() throws Exception {
		// TODO Auto-generated method stub
		super.tearDown();
	}
}

When you run this application it will display message as shown below:

 

Download Select Source Code

Related Tags for Running and testing application :


DMCA.com