问题为Eclipse RCP应用程序运行Junit测试用例

时间:2014-06-10 17:42:58

标签: java eclipse junit swtbot

我在测试Eclipse 4 RCP应用程序的退出处理程序时面临以下异常。

!ENTRY org.eclipse.e4.ui.workbench 2 0 2014-06-10 14:09:22.607
!MESSAGE Could not run processor
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
    at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:220)
    at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:107)
    at org.eclipse.e4.ui.internal.workbench.ModelAssembler.runProcessor(ModelAssembler.java:231)
    at org.eclipse.e4.ui.internal.workbench.ModelAssembler.processModel(ModelAssembler.java:88)
    at org.eclipse.e4.ui.internal.workbench.ResourceHandler.loadMostRecentModel(ResourceHandler.java:220)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application.loadApplicationModel(E4Application.java:395)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:238)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:144)
    at org.eclipse.swtbot.eclipse.core.UITestApplication.start(UITestApplication.java:54)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1426)
Caused by: java.lang.NullPointerException
    at org.eclipse.e4.tools.emf.liveeditor.ModelProcessor.process(ModelProcessor.java:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
    ... 23 more

我的测试用例如下所示

    @RunWith(SWTBotJunit4ClassRunner.class)
public class ExitHandlerTest {

    private static SWTBot bot;

    @BeforeClass
    public static void beforeClass() throws Exception {
        bot = new SWTBot();
    }

    @Test
    public void testExitHandler() {
        SWTBotMenu fileMenu = bot.menu("File");
        Assert.assertNotNull(fileMenu);
        SWTBotMenu exitMenu = fileMenu.menu("Exit");
        Assert.assertNotNull(exitMenu);
        exitMenu.click();
    }

    @AfterClass
    public static void sleep() {
    }

}

我现有的处理程序的代码是

public class ExitHandler {
    @Execute
    public void execute(IWorkbench workbench, EPartService partService, ISaveHandler saveHandler) {
        workbench.close();
    }

}

虽然测试运行正常,但我不确定为什么会出现此异常。

1 个答案:

答案 0 :(得分:0)

您的测试中包含了e4实时模型编辑器,并且您遇到了Eclipse错误426373

我认为这实际上影响了您的测试,因此您可以忽略它。