gpt4 book ai didi

java - GWT Junit 测试用例

转载 作者:行者123 更新时间:2023-11-30 11:40:37 24 4
gpt4 key购买 nike

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

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

 [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>

最佳答案

您收到 404 警告,找不到您的服务。您的 ServiceEntryPoint 定义一定有问题。

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

    target.setServiceEntryPoint(GWT.getModuleBaseURL() + "greet");

另请查看 DevGuide,其中的说明帮助我很好地适应了 GWT RPC 服务: https://developers.google.com/web-toolkit/doc/2.4/DevGuideServerCommunication#DevGuideImplementingServices

关于java - GWT Junit 测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12637981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com