unit testing - How to write a test for GWT servlet? -


I have a GWT application, I would like to test those servlets on server side, some servlets (without senanium, or any other Without the need to do a GUI test with a web-based framework) or in other words I want to simulate the client side of the trial GWT.

There are natural challenges with the test of servlets:

  1. Start the webserver,
  2. customer simulation,
  3. immediately , Passing value for AsyncCallback object. So far, I have been able to understand (although it has not yet been tested), that is: 1. I can start the container by increasing the GWTTestCase 3. I've found a Google doctor about it, so it is possible for wait for async callback to refer to:

    Server Side Test

    Testing the test described above is to help with the client-side code. Test case cover GWTTestCase will either launch a development mode session or a web browser to test a generated JavaScript. On the other hand, the server-side code is run as a native Java in JVM without translation into Javascript, so it is not necessary to run the test of server-side code using GWTTestCase as the base class for your tests. Instead, use JUnit's TestCase and other related classes directly while writing a test for your application's server side code. She said, you want coverage of both GWTTestCase and TestCase code, which will be used on both client and server.

    But there are no examples or deep details about how to get it.

    I do not know how to emulate a customer ... How can I do any ideas?

    Or, if this is not the way to do it, then is there any other way? I like to use native GWT classes, and not some third party framework for test of servlet

    Thank you!

    How about using an embedded jetty frequency ... in the JTT server GVT SDK anyway Includes. Just include gwt-dev.jar in your project and there you go for server-side. Copying the client-side is a whole different story. Javascript for Java scripting / deserialization that is in GWT magic ....

    is a project called gwt-syncproxy which can help :

    Look this way in the code: import junit.framework.Assert; Import org.junit.BeforeClass; Import org.junit.Test; Import org.mortbay.jetty.Server; Import org.mortbay.jetty.servlet.Context; Import org.mortbay.jetty.servlet.ServletHolder; Import com.gdevelop.gwt.syncrpc.SyncProxy; Public class ServletTest {Private server _server; @BeforeClass Public Zero Setup () throws exception {_server = new server (8080); Reference route = new reference (_server, "/", context session); Root.addServlet (New ServletHolder (New MyServiceImpl ()), "/ servlet"); _server.start (); } @Test Public Zero testMethod1 () throws an exception {MyService rpcService = (MyService) SyncProxy.newProxyInstance (MyService.class, "http://127.0.0.1:8080/servlet", "testMethod1"); String result = rpcService.testMethod1 (); Assert.assertTrue (Results! = Null); }}

Comments