首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GWT Junit TestCase

GWT Junit TestCase
EN

Stack Overflow用户
提问于 2012-09-28 18:10:51
回答 1查看 1.1K关注 0票数 2

我想用GWT Junit测试一个RPC。我使用标准的GWT示例并创建以下测试用例:

代码语言:javascript
复制
public class TestGreetingService extends GWTTestCase {
/**
 * Must refer to a valid module that sources this class.
 */
public String getModuleName() {
    return "com.TestGreeting";
}   

/**
 * This test will send a request to the server using the greetServer method
 * in GreetingService and verify the response.
 */
public void testGreetingService() {
    // Create the service that we will test.
    GreetingServiceAsync greetingService = GWT
            .create(GreetingService.class);
    ServiceDefTarget target = (ServiceDefTarget) greetingService;
    target.setServiceEntryPoint(GWT.getModuleBaseURL() + "TestGreeting/greet");

    // Since RPC calls are asynchronous, we will need to wait for a response
    // after this test method returns. This line tells the test runner to
    // wait
    // up to 10 seconds before timing out.
    delayTestFinish(20000);

    // Send a request to the server.
    greetingService.greetServer("GWT User", new AsyncCallback<String>() {
        public void onFailure(Throwable caught) {
            // The request resulted in an unexpected error.
            fail("Request failure: " + caught.getMessage());
        }

        public void onSuccess(String result) {
            // Verify that the response is correct.
            assertTrue(result.startsWith("Hello, GWT User!"));

            // Now that we have received a response, we need to tell the
            // test runner
            // that the test is complete. You must call finishTest() after
            // an
            // asynchronous test finishes successfully, or the test will
            // time out.
            finishTest();
        }
    });
}
}

不幸的是,我得到了以下错误:有人能帮助我吗?我还上传了这个项目: goo.gl/UnFyt

代码语言:javascript
复制
 [WARN] 404 - POST /com.TestGreeting.JUnit/TestGreeting/greet (192.168.1XX.XX) 1427 bytes <br>
Request headers <br>
Host: 192.168.1XX.XX:53577 <br>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19) Gecko/2010031422 <br> Firefox/3.0.19 <br>
Accept-Language: en-us <br>
Accept: */* <br>
Connection: Keep-Alive <br>
Referer: http://192.168.1XX.XX:53577/com.Test...8.1XX.XX:53572 <br>
X-GWT-Permutation: HostedMode <br>
X-GWT-Module-Base: http://192.168.1XX.XX:53577/com.TestGreeting.JUnit/ <br>
Content-Type: text/x-gwt-rpc; charset=utf-8 <br>
Content-Length: 181 <br>
Response headers <br>
Content-Type: text/html; charset=iso-8859-1 <br>
Content-Length: 1427 <br>
EN

回答 1

Stack Overflow用户

发布于 2012-09-28 18:23:57

如果您收到404警告,则无法找到您的服务。您的ServiceEntryPoint定义一定有问题。

尝试为您的同步接口添加@RemoteServiceRelativePath("greet")注释,或者将setServiceEntryPoint更正为

代码语言:javascript
复制
    target.setServiceEntryPoint(GWT.getModuleBaseURL() + "greet");

还要看一下DevGuide,其中的说明对我很好地适应了GWT服务:https://developers.google.com/web-toolkit/doc/2.4/DevGuideServerCommunication#DevGuideImplementingServices

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12637981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档