How to use web.xml or call servlet init() when using GWTTestCase
I a开发者_如何转开发m using GWTTestCase class and I have to specify any servlets to use in module.gwt.xml file using
<servlet path="/somepath" class="com.example.SomeServlet"/>.
The actual requirement is to load other servlets that initialize resources (using GenericServlet.init()
method) in order to make the tests run. web.xml is the obvious choice as this works in normal application setup. Also it would be useful to declare initialisation parameters.
How do I get GWT to read web.xml file when doing unit testing?
I think you'll have to:
- extend your servlet and override the init() method to pass the appropriate parameters
- configure that servlet in your
*.gwt.xml
(I'd suggest using a module specifically for the test(s), so that the<servlet>
don't clutter your production module)
As an alternative, because this looks more like an integration test than a unit test, don't use a GWTTestCase but rather WebDriver/Selenium and a lightweight servlet container configured specifically for your test (e.g. Jetty).
I would try Google Guice with its servlet extension. It allow you to dynamically bind servlets instead of web.xml. Real nice. You can load a specific testing module for example. The official docu has examples for the servlet extension. Hopefully it will provide you with what you need.
精彩评论