我正在尝试使用文档中描述的方法对我的 Struts2 操作运行一个简单的测试。但是,测试类没有实例化,而是给了我以下异常:
Results :
Tests in error:
initializationError(net.myorg.myProj.actions.HomeTest): Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
这是我的测试类的代码:
import com.opensymphony.xwork2.ActionProxy;
import org.apache.struts2.StrutsTestCase;
import org.junit.Test;
import static org.junit.Assert.*;
public class HomeTest extends StrutsTestCase
{
@Test
public void testExecute() throws Exception
{
System.out.println("getting proxy");
ActionProxy proxy = getProxy();
System.out.println("got proxy");
String result = proxy.execute();
System.out.println("got result: " + result);
assertEquals("Landing", result, "landing");
}
private ActionProxy getProxy()
{
return getActionProxy("/");
}
}
我究竟做错了什么?
编辑:在我的 pom.xml 中,我有以下内容:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
我猜这是导致这个问题的原因,即当我只是从 IDE 中而不是通过 Web 浏览器运行单元测试时,没有正确下载或包含 jar?我如何自己包含这个 jar,以便运行单元测试?