Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何运行Struts2单元测试?_Java_Unit Testing_Struts2_Junit_Struts2 Junit Plugin - Fatal编程技术网

Java 如何运行Struts2单元测试?

Java 如何运行Struts2单元测试?,java,unit-testing,struts2,junit,struts2-junit-plugin,Java,Unit Testing,Struts2,Junit,Struts2 Junit Plugin,Struts2文档描述了如何为Struts2编写单元测试。但是,一旦这些测试被编写出来,我如何才能真正运行它们呢?例如,通常我会使用Eclipse/Netbeans为类创建一个新的JUNIT测试,然后在Eclipse/Netbeans中运行测试 但是,Struts2测试也不能这样做,因为除非tomcat或其他容器正在运行,否则不能运行Struts2测试,否则会出现缺少servlet api之类的错误。(您通常得到的JavaEEJAR只包含接口和抽象类,它们的实现只附带一个类似tomcat/gla

Struts2文档描述了如何为Struts2编写单元测试。但是,一旦这些测试被编写出来,我如何才能真正运行它们呢?例如,通常我会使用Eclipse/Netbeans为类创建一个新的JUNIT测试,然后在Eclipse/Netbeans中运行测试

但是,Struts2测试也不能这样做,因为除非tomcat或其他容器正在运行,否则不能运行Struts2测试,否则会出现缺少servlet api之类的错误。(您通常得到的JavaEEJAR只包含接口和抽象类,它们的实现只附带一个类似tomcat/glassfish的容器)


那么,在编写Struts 2测试之后,如何运行它们呢?

为了解决缺少servlet API的问题,请向POM添加以下依赖项

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.4</version>
    <type>jar</type>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
    <type>jar</type>
    <scope>test</scope>
</dependency>

javax.servlet
servlet api
2.4
罐子
假如
javax.servlet.jsp
jsp api
2.1
罐子
测试

非常类似于@coding\u idiot你是对的,我必须在pom.xml中添加与那家伙相同的行,以使测试工作正常。如果你想补充这一点作为回答,我可以接受。