gpt4 book ai didi

GWT 同步代理测试

转载 作者:行者123 更新时间:2023-11-28 20:56:57 25 4
gpt4 key购买 nike

我使用标准 GWT 示例创建了一个新的 Web 应用程序项目。然后我想用下面的测试类来测试 greetingserviceimpl。我不知道问题出在哪里。我还上传了项目:http://ul.to/1pz1989y

public class RPCTest extends GWTTestCase {

@Override
public String getModuleName() {
// TODO Auto-generated method stub
return "de.GreetingTest";
}

public void testGreetingAsync() {
GreetingServiceAsync rpcService = (GreetingServiceAsync) SyncProxy.newProxyInstance(GreetingServiceAsync.class,"http://127.0.0.1:8888/GreetingTest.html?gwt.codesvr=127.0.0.1:9997");
rpcService.greetServer("GWT User", new AsyncCallback<String>() {
public void onFailure(Throwable ex) {
ex.printStackTrace();
fail(ex.getMessage());
}
public void onSuccess(String result) {
assertNotNull(result);
finishTest();//
}
});
delayTestFinish(1000);
}

验证新编译的单元 在第一遍中忽略了 1 个有编译错误的单元。
使用 -strict 或 -logLevel 设置为 TRACE 或 DEBUG 进行编译以查看所有错误。
[错误] 第 17 行:没有可用于类型 com.gdevelop.gwt.syncrpc.SyncProxy 的源代码;您是否忘记继承所需的模块?
[错误] 无法找到类型“de.client.RPCTest”
[错误] 提示:以前的编译器错误可能导致此类型不可用
[错误] 提示:检查模块的继承链;它可能没有继承所需的模块,或者模块可能没有正确添加其源路径条目

最佳答案

您的 rpc 服务是异步的 - 它没有在 testGreetingAsync 方法返回时完成。 GWTTestCase(但您正在扩展 TestCase,您可能应该更改它)支持此方法 - 在方法末尾调用 delayTestFinish 以指示测试是异步的。然后,在成功后调用 finishTest

public class RPCtest extends GWTTestCase {
public void testGreetingAsync() {
GreetingServiceAsync rpcService = (GreetingServiceAsync) SyncProxy.newProxyInstance(GreetingServiceAsync.class,"http://127.0.0.1:8888/Tests.html?gwt.codesvr=127.0.0.1:9997");
rpcService.greetServer("GWT User", new AsyncCallback() {
public void onFailure(Throwable ex) {
//indicate that a failure has occured
ex.printStackTrace();
fail(ex.getMessage());//something like this
}
public void onSuccess(Object result) {
//verify the value...
assertNotNull(result);

//Then, once sure the value is good, finish the test
finishTest();//This tells GWTTestCase that the async part is done
}
});
delayTestFinish(1000);//1000 means 'delay for 1 second, after that time out'
}
}

编辑更新的问题:

The test class 'de.RPCTest' was not found in module 'de.GreetingTest'; no compilation unit for that type was seen

就像您的常规 GWT 代码必须位于 client 包中一样,您的 GWTTestCase 代码也必须如此 - 这也作为 JavaScript 运行,因此它可以像在浏览器中一样被正确测试。根据错误,我猜你的 EntryPoint 等在 de.client 中 - 这个测试也应该在那里。

关于GWT 同步代理测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12608256/

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