Re: why the code passes Servlet container test but fails in StrutsTestCase
This shouldn't even compile since you're attempting to return a value. On Feb 13, 2016 11:26 PM, "JOSE L MARTINEZ-AVIAL" wrote: > The method execute has void as a return type, instead of a String. > > 2016-02-13 2:26 GMT-05:00 小唐 <644282...@qq.com>: > > > Hi, > > > > I was trying to use StrutsTestCase to write a test for a Bean, which has > a > > member of String[]. The code runs perfectly in servlet container(Tomcat), > > but fails as a mock test. In EditActionTest.java, assertNotNull("The > action > > is null but should not be.", action) still works fine, but String result > = > > actionProxy.execute() returns the result as "error" instead of "success". > > All the related codes are listed below. > > > > Can anyone give me a hint? > > Thanks in advance! Tom > > > > Person.java > > public class Person{ > >String[] models = new String[]{"Ford", "Nissan"}; > > > >public void setModels(String[] models){ > > this.models = models; > >} > > > >public String[] getModels(){ > > return models; > >} > > } > > > > Edit.java > > public class EditAction extends ActionSupport{ > >Person personBean; > > > >public void execute(){ > > return SUCCESS; > >} > > } > > > > struts.xml > > > > > > /edit.jsp > > /thankyou.jsp > > > > > > > > edit.jsp > > <%@ taglib prefix="s" uri="/struts-tags" %> > > > > > > > > > > > > EditActionTest.java > > public class EditActionTest extends StrutsTestCase { > >@Test > >public void testExecuteValidationPasses() throws Exception { > > request.setParameter("personBean.models", new String[]{"Ford", > > "Nissan"}); > > ActionProxy actionProxy = getActionProxy("/edit.action") ; > > EditAction action = (EditAction) actionProxy.getAction(); > > assertNotNull("The action is null but should not be.", action); > > String result = actionProxy.execute(); > > assertEquals("The execute method did not return " + > > ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, > result); > >} > > } >
Re: why the code passes Servlet container test but fails in StrutsTestCase
The method execute has void as a return type, instead of a String. 2016-02-13 2:26 GMT-05:00 小唐 <644282...@qq.com>: > Hi, > > I was trying to use StrutsTestCase to write a test for a Bean, which has a > member of String[]. The code runs perfectly in servlet container(Tomcat), > but fails as a mock test. In EditActionTest.java, assertNotNull("The action > is null but should not be.", action) still works fine, but String result = > actionProxy.execute() returns the result as "error" instead of "success". > All the related codes are listed below. > > Can anyone give me a hint? > Thanks in advance! Tom > > Person.java > public class Person{ >String[] models = new String[]{"Ford", "Nissan"}; > >public void setModels(String[] models){ > this.models = models; >} > >public String[] getModels(){ > return models; >} > } > > Edit.java > public class EditAction extends ActionSupport{ >Person personBean; > >public void execute(){ > return SUCCESS; >} > } > > struts.xml > > > /edit.jsp > /thankyou.jsp > > > > edit.jsp > <%@ taglib prefix="s" uri="/struts-tags" %> > > > > > > EditActionTest.java > public class EditActionTest extends StrutsTestCase { >@Test >public void testExecuteValidationPasses() throws Exception { > request.setParameter("personBean.models", new String[]{"Ford", > "Nissan"}); > ActionProxy actionProxy = getActionProxy("/edit.action") ; > EditAction action = (EditAction) actionProxy.getAction(); > assertNotNull("The action is null but should not be.", action); > String result = actionProxy.execute(); > assertEquals("The execute method did not return " + > ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, result); >} > }
why the code passes Servlet container test but fails in StrutsTestCase
Hi, I was trying to use StrutsTestCase to write a test for a Bean, which has a member of String[]. The code runs perfectly in servlet container(Tomcat), but fails as a mock test. In EditActionTest.java, assertNotNull("The action is null but should not be.", action) still works fine, but String result = actionProxy.execute() returns the result as "error" instead of "success". All the related codes are listed below. Can anyone give me a hint? Thanks in advance! Tom Person.java public class Person{ String[] models = new String[]{"Ford", "Nissan"}; public void setModels(String[] models){ this.models = models; } public String[] getModels(){ return models; } } Edit.java public class EditAction extends ActionSupport{ Person personBean; public void execute(){ return SUCCESS; } } struts.xml /edit.jsp /thankyou.jsp edit.jsp <%@ taglib prefix="s" uri="/struts-tags" %> EditActionTest.java public class EditActionTest extends StrutsTestCase { @Test public void testExecuteValidationPasses() throws Exception { request.setParameter("personBean.models", new String[]{"Ford", "Nissan"}); ActionProxy actionProxy = getActionProxy("/edit.action") ; EditAction action = (EditAction) actionProxy.getAction(); assertNotNull("The action is null but should not be.", action); String result = actionProxy.execute(); assertEquals("The execute method did not return " + ActionSupport.SUCCESS + " but should have.", ActionSupport.SUCCESS, result); } }