testing - StrutsTestCase/WEB-INF/web.xml 没有找到

标签 testing struts web.xml

我在netbeans7.0下用StrutsTestCase2.4搭配struts1.3
运行testCase时显示:

Error initializing action servlet
javax.servlet.UnavailableException: The /WEB-INF/web.xml was not found.

我用谷歌搜索了这个问题,建议通过 setContextDirectory(new File("../web")); 解决:

protected void setUp() throws Exception
{
    super.setUp();
    setContextDirectory(new File("../web"));
 }

但我不太确定 new File() 的位置应该是什么。
我的文件树是

|───build
│   ├───test
│   │   └───classes
│   │       └───com
│   │           └───stolon
│   │               ├───common
│   │               ├───database
│   │               ├───helpers
│   │               └───struts
│   └───web
│       ├───META-INF
│       └───WEB-INF
│           ├───classes
│           │   └───com
│           │       └───stolon
│           │           ├───algorithm
│           │           ├───database
│           │           ├───helpers
│           │           ├───servlet
│           │           ├───structures
│           │           └───struts
│           └───lib
├───nbproject
│   └───private
├───src
│   ├───conf
│   └───java
│       └───com
│           └───stolon
│               ├───algorithm
│               ├───database
│               ├───helpers
│               ├───servlet
│               ├───structures
│               └───struts
├───test
│   └───com
│       └───stolon
│           ├───common
│           ├───database
│           ├───helpers
│           └───struts
└───web
    ├───META-INF
    └───WEB-INF

我的测试文件在 test-com-stolon-struts 下。

最佳答案

我刚遇到这个。当测试运行时,WEB-INF/web.xml(可能还有 struts-config.xml 等)必须在您的类路径中。确保 netbeans 将/build/web/放在测试类路径中。

如果您使用的是 Maven,您将添加 WEB-INF/*.xml 作为测试资源。

    <testResources>
        <testResource>
            <directory>WEB-INF</directory>
            <targetPath>/WEB-INF</targetPath>
            <includes>
                <include>*.xml</include>
            </includes>
        </testResource>
    </testResources>

关于testing - StrutsTestCase/WEB-INF/web.xml 没有找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6260218/

相关文章:

asp.net - 如何测试模拟多个并发请求的webservice

unit-testing - Java EE 测试策略

java - Struts 表单 bean 对象创建和连接池

java - JSTL 从对象数组中获取值

java - WAR 不会部署到 Tomcat 7.0.19

java - 从 web.xml 中的库导入 servlet

unit-testing - 如何测试具有 N 个不同路径的函数?

testing - 我如何测试 Zkoss 中注解 @Listen 的正确性?

css - 如何使 s :radio ordered list?

java - Servlet 过滤器无法正常工作