???????Struts2??Action?????????
???????????? ???????[ 2013/9/29 16:03:40 ] ????????
?????????д????Struts2???????????????????????????Struts2??Spring??Java?????
????????д??????????Struts2??Action????????????????????????????????
?????????????д????д??????£????????90?????
???????????????????????????????д???????У??????????????????
?????????????????????????-?????
????1.???????????????jar????
????struts.core??struts?????jar??
????spring-core-3.2.0.RELEASE.jar
?????????????????Щ?????翴??????????????Struts2?????Spring?????????
??????????????????java.lang.NoClassDefFoundError: org/springframework/core/io/ResourceLoader??
????spring-test-3.2.3.RELEASE.jar
????Junit??jar??
????Tomcat??Server Rumtime lib??
????2.???Action??
public class UserAction {
public String list(){
return "success";
}
}
|
??3.???????????
package unittest;
import org.apache.struts2.StrutsTestCase;
import org.junit.Test;
import action.UserAction;
import com.opensymphony.xwork2.ActionProxy;
public class ActionUnitTest extends StrutsTestCase {
// ??д????????????????????????
protected String[] getContextLocations() {
return new String[] { "struts.xml" };
}
@Test
public void testExecute() throws Exception {
ActionProxy proxy = getActionProxy("/unitTest");
assertNotNull(test);
String result = proxy.execute();
assertEquals("success"?? result);
}
}
|
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!– Development Mode –>
<constant name="struts.devMode" value="true" />
<package name="manager" namespace="/" extends="struts-default">//????default
<action name="unitTest" class="action.UserAction" method="list">
<result name="success">unitTest.jsp
</result>
</action>
</package>
</struts>
|
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
????URL??http://localhost:8080/Struts2UnitDemo/unitTest.action
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11