我现在正在用gwt做一个项目。我必须使用 Eclipse Luna、JUnit 和 Mockito 测试演示者,并且在做任何事情时遇到问题。
在我用mockito失败后,我发现了GwtMockito并尝试了一下。我用这个例子开始了:Github GwtMockito的例子
我的测试类如下所示:
@RunWith(GwtMockitoTestRunner.class)
public class GamePresenterTest {
@GwtMock private GameServiceAsync gameService;
@GwtMock private LobbyPresenter lobbyPresenter;
@GwtMock private EventBus eventBus;
@GwtMock private Display gameView;
@GwtMock private User user;
@GwtMock private Player player;
@GwtMock private ClickEvent event;
private GamePresenter presenter;
private String username = "name";
private String gameTitle = "title";
@Before
public void setUp() {
System.out.println("TODO: set up");
}
@Test
public void testActionTableClicked() {
System.out.println("TODO: add test");
}
}
当我运行它时,我得到这个
java.lang.NoClassDefFoundError: javassist/NotFoundException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.getConstructor(Class.java:1825)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: javassist.NotFoundException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 18 more
当我删除@RunWith(GwtMockitoTestRunner.class)
时,我收到另一条消息,告诉我应该使用 initMocks,但我也不知道如何做到这一点。没有@RunWith(GwtMockitoTestRunner.class)
和@GwtMock
的东西,当然一切正常。
我希望有人能帮忙,因为我的项目在几周后结束。
看起来你需要javassist-<version>.jar
.将其添加到您的类路径中,它应该可以工作