我目前正在与gwt做一个项目。我必须使用Eclipse Luna,JUnit和Mockito测试演示者,并且在执行任何操作时都遇到问题。
我在模仿失败后,发现了GwtMockito并尝试了。我使用此示例开始:Github GwtMockito example
我的Test类看起来像这样:
@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
。将其添加到您的类路径中,它应该可以工作
关于java - Gwt Mockito:@RunWith(GwtMockitoTestRunner.class)导致异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35066742/