记录器在 AsyncCallback 内部不工作
Logger not working inside AsyncCallback
我在使用 GWT 单元测试进行日志记录时遇到问题:
logInfo("Creating Stuff: " + stuffAutoBeanSerializer.encodeData(stuff)); // Logging works and showing in the IntelliJ console
myService.createStuff(stuff, new AsyncCallback<Stuff>() {
@Override
public void onFailure(Throwable throwable) {
logSevere(throwable.getMessage()); // Not showing in the console
}
@Override
public void onSuccess(Stuff stuff) {
logInfo("Created Stuff: " + stuffAutoBeanSerializer.encodeData(stuff)); // not showing in the console
}
});
即使请求是 onSuccess
因为数据存储在数据库中。这可能是什么问题?
你的测试方法的其余部分丢失了,但问题几乎可以肯定是你没有告诉测试用例它是异步的,所以当方法无异常返回时,测试基础设施假定测试通过。
在异步 GWTTestCase 中,您必须使用delayTestFinish(millis)
来指示测试不会在returns时完成,然后finishTest()
(可能在你的 onSuccess 中)表示测试通过。如果 finishTest()
没有及时调用(或根本没有),测试将被认为失败。
我在使用 GWT 单元测试进行日志记录时遇到问题:
logInfo("Creating Stuff: " + stuffAutoBeanSerializer.encodeData(stuff)); // Logging works and showing in the IntelliJ console
myService.createStuff(stuff, new AsyncCallback<Stuff>() {
@Override
public void onFailure(Throwable throwable) {
logSevere(throwable.getMessage()); // Not showing in the console
}
@Override
public void onSuccess(Stuff stuff) {
logInfo("Created Stuff: " + stuffAutoBeanSerializer.encodeData(stuff)); // not showing in the console
}
});
即使请求是 onSuccess
因为数据存储在数据库中。这可能是什么问题?
你的测试方法的其余部分丢失了,但问题几乎可以肯定是你没有告诉测试用例它是异步的,所以当方法无异常返回时,测试基础设施假定测试通过。
在异步 GWTTestCase 中,您必须使用delayTestFinish(millis)
来指示测试不会在returns时完成,然后finishTest()
(可能在你的 onSuccess 中)表示测试通过。如果 finishTest()
没有及时调用(或根本没有),测试将被认为失败。