经过几个小时的网上冲浪寻找这个问题的答案,最后我决定在这里发布这个问题。
我正在使用 struts 2 junit 插件来测试 struts 2 应用程序的一些操作。主要的 struts 配置文件(struts.xml)是这样的:
<struts>
<package name="default" extends="struts-default">
</package>
<include file="/com/jmc/textil/productcard/action/productcard.xml"/>
<!--More includes...-->
</struts>
Run Code Online (Sandbox Code Playgroud)
产品卡.xml 文件:
<struts>
<!--Some other packages...-->
<package name="productClasification" namespace="/productClasification" extends="default">
<!--More actions...-->
<action name="edit" method="edit" class="com.jmc.textil.productcard.action.ProductClasificationAction">
<result>/main/jsp/json_struts2.jsp</result>
</action>
</package>
</struts>
Run Code Online (Sandbox Code Playgroud)
我有一个扩展 StrutsTestCase 的测试类,以及“/productClasification/edit”操作的测试方法。当进行以下调用时:
ActionProxy proxy = getActionProxy("/productClasification/edit.action");
ProductClasificationAction clasificationAction =
(ProductClasificationAction) proxy.getAction();
Run Code Online (Sandbox Code Playgroud)
由于无法找到该操作,因此引发异常。默认情况下,StrutsTestCase 使用 struts.xml,但是其他 struts 配置 xml 文件呢?
提前致谢。