servletunit.struts.ExceptionDuringTestError: A NullPointerException was thrown. This may indicate an error in your ActionForm, or it may indicate that the Struts ActionServlet was unable to find struts config file. TestCase is running from D:/workspace/Struts1UnitTestProject directory. Context directory has not been set. Try calling setContextDirectory() with a relative or absolute path. struts config file must be found under the context directory, the directory the test case is running from, or in the classpath.
the approach as below:
protected void setUp() throws Exception {
super.setUp();
setContextDirectory(new File("WebRoot"));
}
the approach as below:
protected void setUp() throws Exception {
super.setUp();
setContextDirectory(new File("WebRoot"));
}
本文探讨了在Struts1单元测试中遇到的一个NullPointerException异常及其可能的原因。异常提示表明可能是ActionForm错误或找不到struts配置文件。文章提供了一个解决方法,即通过设置正确的上下文目录来确保struts配置文件被正确加载。
3270

被折叠的 条评论
为什么被折叠?



