Reputation: 5522
Can I write test cases for struts action class? That is, I would like to test execute method of an existing struts action class, where I can check what is the return ActionForward and also the content of form which is being set up in execute method. An example would be helpful.
Thanks Kamal
Upvotes: 2
Views: 7017
Reputation: 61715
As far as I can tell, there is only StrutsTestCase. But this is for JUnit 3, not JUnit 4, so it seems to be pretty out of date.
The other alternatives you have come from How perform Junit tests with Struts - Ibatis, which suggest HttpUnit (again pretty old) or Cactus (which has been retired).
If I had to, I would start with StrutsTestCase
. Here is a sample Test Case from the site:
public class TestLoginAction extends MockStrutsTestCase {
public TestLoginAction(String testName) { super(testName); }
public void testSuccessfulLogin() {
setRequestPathInfo("/login");
addRequestParameter("username","deryl");
addRequestParameter("password","radar");
actionPerform();
verifyForward("success");
}
}
I have used StrutsTestCase
a long time ago, and as far as I can remember it worked fairly well.
Upvotes: 1