首页 > StrutsTestCase遭遇missing configuration resources

StrutsTestCase遭遇missing configuration resources

我想要对我的一个Struts应用里的Action进行单元测试,所以采用了StrutsTestCase这款框架,本来觉得这个框架看上去挺好用的,结果从昨天下午一直折腾到现在都没成功过一次。
现在的错误情况是这样的,当我运行的时候会显示"missing configuration resources for path /WEB-INF/web.xml"错误。
恰好它的FAQ里有这么一条信息,说是设置classpath,我的应用路径是E:/JavaPros/stolon/STOLONCAS/web/,于是我在classpath的开头加上了这个路径,但是运行依然失败,错误信息还是一样的。
然后我又看到有一种setConfigFile()的方法,于是我尝试了一下在里面指定相对路径或者绝对路径,但是结果依然是失败。只是错误信息变成了"Missing configuration resource for path E:/JavaPros/stolon/STOLONCAS/build/web/WEB-INF/struts-config.xml"。这是很让我不解的,因为很确定我的struts-config.xml在这么个路径里面。
下面是我的单元测试的setUp()方法:

public void setUp() throws Exception {
        super.setUp();
        File web = new File("E:/JavaPros/stolon/STOLONCAS/web/");
        this.setContextDirectory(web);
        this.setConfigFile("E:/JavaPros/stolon/STOLONCAS/web/WEB-INF/web.xml");
        this.setConfigFile("E:/JavaPros/stolon/STOLONCAS/web/WEB-INF/struts-config.xml");
    }

你可以试着把

File web = new File("E:/JavaPros/stolon/STOLONCAS/web/");
this.setContextDirectory(web);
this.setConfigFile("E:/JavaPros/stolon/STOLONCAS/web/WEB-INF/web.xml");
this.setConfigFile("E:/JavaPros/stolon/STOLONCAS/web/WEB-INF/struts-config.xml");

改成

setContextDirectory("web"); 
//在你的工程 web/WEB-INF 目录下放有 web.xml 和 struts-config.xml

这样改好之后,应该就可以了,不行的话,再加上以下的代码再试试

setConfigFile("/WEB-INF/web.xml");
setConfigFile("/WEB-INF/struts-config.xml")
【热门文章】
【热门文章】