gpt4 book ai didi

java - 使用 Jukito 测试时 GWT 计时器 UnsatisfiedLinkError

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

我正在使用 Jukito 来测试 GWTP Presenter,在其中一个具有计时器作为重复任务字段的演示器中,我抛出了此异常。

我正在运行 GWT 2.8.2、GWTP 1.6、JUnit 4 和 Jukito 1.5

测试如下所示:

@RunWith(JukitoRunner.class)
public class MyPresenterTest {

@Inject
MyPresenter presenter;

@Test
public void prepareFromRequestTest(EventBus eventBus,
MyServiceAsync MyService) {

PlaceRequest placeRequest = new PlaceRequest.Builder()
.nameToken(NameTokens.getMyPlace())
.with("aParam", "0110")
.build();

Data data = DataTestFactory.createData();

AsyncStubber.callSuccessWith(data)
.when(myService)
.requestDataToServer(eq("0110"), any());

// the timer scheduleRepeating is called in here:
presenter.prepareFromRequest(placeRequest);
}
}

即使像下面这样的基本测试也会失败:

@RunWith(JukitoRunner.class)
public class GwtTimerTest {

@Test
public void testTimer() {
Timer timer = new Timer() {
@Override
public void run() {
System.out.println("timer");
}
};

timer.schedule(1000);
}
}

这是完整的异常(exception):

java.lang.UnsatisfiedLinkError: com.google.gwt.user.client.Timer.createCallback(Lcom/google/gwt/user/client/Timer;I)Lcom/google/gwt/core/client/JavaScriptObject;

at com.google.gwt.user.client.Timer.createCallback(Native Method)
at com.google.gwt.user.client.Timer.schedule(Timer.java:98)
at my.test (Redacted.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.jukito.InjectedStatement.evaluate(InjectedStatement.java:108)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:305)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:365)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:330)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:78)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:328)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:65)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:292)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:305)
at org.junit.runners.ParentRunner.run(ParentRunner.java:412)
at org.jukito.JukitoRunner.run(JukitoRunner.java:227)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

我想我可以捕获一个错误(UnsatisfiedLinkError 不在 GWT 的 JRE 模拟中),但这不会让我正确测试计时器安排后会发生什么。任何人都可以重现它或知道如何修复它?

最佳答案

避免使用Timer,而使用com.google.gwt.core.client.Scheduler。然后,您可以在产品代码中绑定(bind)实际的调度程序,并在测试中绑定(bind) StubScheduler

您可以使用 gwtmockito 使 Timer 正常工作,但我因为您已经在使用注入(inject),所以您确实应该隐藏抽象后面的任何 native 或 GWT.create 调用,并使用替代实现进行测试。

关于java - 使用 Jukito 测试时 GWT 计时器 UnsatisfiedLinkError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55041645/

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