1

基本上,我正在尝试运行一个简单的单元测试,但是当我使用 freemarker 作为结果类型时无法使其工作。其他类型,如 jsp 或 redirectAction 工作正常。我错过了什么?

ForwardActionTest.java:

public class ForwardActionTest extends StrutsSpringTestCase {
    ....
    public void testExecuteAction() throws Exception {
        String output = executeAction("/home.do"); <--- Exception points here
        ...
    }
}

struts.xml

<action name="home" class="forwardAction">
    <result type="freemarker">templates/home.ftl</result>
</action>

模板/home.ftl

Hello! You are home!

堆栈跟踪:

javax.servlet.ServletException: Error code [500], Error: [Template /templates/home.ftl not found.]
at org.apache.struts2.StrutsTestCase.executeAction(StrutsTestCase.java:120)
at com.telus.ccs.survey.web.action.ForwardActionTest.testExecuteAction(ForwardActionTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
4

0 回答 0