Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
Unit testing 使用GWTTestCase时如何使用web.xml或调用servlet init()_Unit Testing_Gwt - Fatal编程技术网

Unit testing 使用GWTTestCase时如何使用web.xml或调用servlet init()

Unit testing 使用GWTTestCase时如何使用web.xml或调用servlet init(),unit-testing,gwt,Unit Testing,Gwt,我使用的是GWTTestCase类,必须使用 <servlet path="/somepath" class="com.example.SomeServlet"/>. 。 实际需求是加载初始化资源的其他servlet(使用GenericServlet.init()方法),以便运行测试。web.xml显然是一种选择,因为它适用于正常的应用程序设置。声明初始化参数也很有用 在进行单元测试时,如何让GWT读取web.xml文件 我会尝试Google Guice及其servlet扩展。它

我使用的是GWTTestCase类,必须使用

<servlet path="/somepath" class="com.example.SomeServlet"/>.
实际需求是加载初始化资源的其他servlet(使用
GenericServlet.init()
方法),以便运行测试。web.xml显然是一种选择,因为它适用于正常的应用程序设置。声明初始化参数也很有用


在进行单元测试时,如何让GWT读取web.xml文件

我会尝试Google Guice及其servlet扩展。它允许您动态绑定servlet,而不是web.xml。真不错。例如,您可以加载特定的测试模块。官方文档中有servlet扩展的示例。希望它能为您提供您所需要的。

我想您必须:

  • 扩展servlet并重写init()方法以传递适当的参数
  • *.gwt.xml
    中配置该servlet(我建议使用专门用于测试的模块,以便
    不会使生产模块混乱)

  • 作为替代方案,因为这看起来更像是一个集成测试而不是单元测试,所以不要使用GWTTestCase,而是使用WebDriver/Selenium和专门为您的测试配置的轻量级servlet容器(例如Jetty)。

    那么,如何安装Guice过滤器:|?这是一个示例: