Posted by Vikas Hazrati on Thursday, June 11, 2009
We have a legacy application and a lot of presentation code is written using Struts 1.2.4. For unit tetsing the action classes we used the following approach.
StrutsTestCase provides both a Mock Object approach and a Cactus approach to actually run the Struts ActionServlet, allowing you to test your Struts code with or without a running servlet engine. When you want to execute your tests as a part of the continuous integration environment in which all the unit tests should execute without deploying the application to the container.
For the following entry of Struts-config.xml
<action path="/login" type="com.dnbi.simpleaction.LoginAction" name="loginForm" input="/login/login.jsp" scope="request">
<forward name="success" path="/action/simpleAction" />
<forward name="failure" path="/failurePath" />
</action>
and for the following action,
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
ActionErrors errors = new ActionErrors();
String username = ((LoginForm) form).getUsername();
String password = ((LoginForm) form).getPassword();
if ((!username.equals("vikas")) || (!password.equals("pass")))
errors.add("password", new ActionError("error.password.mismatch"));
if (!errors.isEmpty()) {
saveErrors(request, errors);
return new ActionForward(mapping.getInput());
}
HttpSession session = request.getSession();
session.setAttribute("authentication", username);
return mapping.findForward("success");
}
the test would look like this
Read the rest of this entry »
Posted in Better Software, Java, testing | 3 Comments »
Posted by Vikas Hazrati on Monday, June 9, 2008

If you are getting the above error message in Eclipse IDE, while running your test case, just make sure that you have the test class as a part of the “eclipse source folder” definition.
Easiest way. Right click on the folder –> Build Path –>Use as source folder
Done.
Posted in Java, testing | 18 Comments »
Posted by Vikas Hazrati on Wednesday, December 5, 2007
We use Fitnesse as the acceptance testing tool for our projects. Many a times it becomes a necessity to remotely debug how the fitnesse fixture is running through your code.
This blog would try to explain how you can easily set up a remote debugging session between Fitnesse and Eclipse so that you can debug through the code as your fixture is being executed.
In your Eclipse IDE
1. Goto Run->Open Debug Dialog
2. Right click on Remote Java Application option in the left hand menu tree and say new
3. Create a remote java application debug configuration like this
Read the rest of this entry »
Posted in Java, testing | Tagged: acceptance testing, debugging, Eclipse, Fitnesse, Remote debugging | 5 Comments »
Posted by Vikas Hazrati on Monday, July 30, 2007
Many times you need sample data to be used as the set up data for your test cases. An easy way to extract data from a database into an XML file is as follows
The code sample below is mentioned for Postgres database however can be used for any database.
Read the rest of this entry »
Posted in dbunit, testing | 4 Comments »
Posted by Vikas Hazrati on Sunday, July 29, 2007
We are using HSQLDB (1.8.0.1) as the in memory database for our DBUNIT (2.1) test cases. Suddenly when trying to insert from our XML datafile to a boolean field we started getting an error which said
WARNING – APP_USER.ACCOUNT_EXPIRED data type (16, ‘BOOLEAN’) not recognized and will be ignored. See FAQ for more information.
It looks like the SQL type Types.BOOLEAN is not handled correctly. The way around is that
- Create a new data type factory that extends the DBUnit class DefaultDataTypeFactory like this
Read the rest of this entry »
Posted in dbunit, hsqldb, testing | 3 Comments »