????4.???Service??
package action;
import org.springframework.stereotype.Service;
@Service
public class UserService {
/**
* ????????????
*/
public String getName(String name) {
// ?????????????????Dao??ò????????????
// ?????????????Struts2Spring?????У?Struts??Action??Spring????Service??
// Struts2Spring+Hibernate/Mybatis???????????н????
return name;
}
}
????5.???????Action??
package unittest;
import org.apache.struts2.StrutsSpringTestCase;
import org.junit.Test;
import action.UserAction;
import com.opensymphony.xwork2.ActionProxy;
/**
* ????StrutsSpring??????????????StrutsSpringTestCase?????
* ??????????Struts????????StrutsTestCase??
*
* @author http://blog.csdn.net/fansunion/
*
*/
public class ActionUnitTest extends StrutsSpringTestCase {
// ??д????????????????????????
protected String[] getContextLocations() {
return new String[] { "struts.xml"?? "applicationContext-spring.xml" };
}
@Test
public void testExecute() throws Exception {
ActionProxy proxy = getActionProxy("/unitTest");
UserAction test = (UserAction) proxy.getAction();
assertNotNull(test);
String result = proxy.execute();
assertEquals("success"?? result);
}
}