WorkbenchPage.busyShowView中的NullPointerException

Ste*_* S. 6 eclipse-plugin tycho e4

我有一个简单的视图,通常在我的Eclipse插件(4.5.2)中注册,当我使用插件启动Eclipse实例时,它可以正常工作.它仍然适用于相应的测试用例,它具有以下方法:

@Before
public void setUp() throws Exception {
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (IViewReference viewReference : activePage.getViewReferences()) {
        activePage.hideView(viewReference);
    }
    activePage.showView("org.acme.MyView");
}
Run Code Online (Sandbox Code Playgroud)

然而,当我使用Tycho(0.22,0.24或0.25)运行相同的测试时,我得到以下异常:

java.lang.NullPointerException: null
    at org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:1271)
    at org.eclipse.ui.internal.WorkbenchPage$12.run(WorkbenchPage.java:4238)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:4234)
    at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:4214)
    at org.acme.MyViewTest.setUp(MyViewTest.java:39)
Run Code Online (Sandbox Code Playgroud)

第谷代码很简单:

<plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>tycho-surefire-plugin</artifactId>
    <configuration>
        <providerHint>junit4</providerHint>
        <useUIHarness>true</useUIHarness>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我发现了这个bug以及更多,但我没有发现任何解释为什么它只会在第谷失败.我找不到任何关于如何解决这个问题.

那我做错了什么?我如何解决它?

And*_*ewe 3

我的猜测是,您的测试运行时中缺少成熟的 Eclipse 工作台所需的 \xe2\x80\x99s 以及 PDE 添加的内容,但第谷没有\xe2\x80\x99t。(默认情况下,Tycho 仅将您的(传递)依赖项添加eclipse-test-plugin到测试运行时。)

\n\n

尝试将以下内容添加到您的tycho-surefire-plugin执行中:

\n\n
<configuration>\n  <!-- ... ->\n  <dependencies>\n    <dependency>\n      <artifactId>org.eclipse.e4.rcp</artifactId>\n      <type>eclipse-feature</type>\n    </dependency>\n  </dependencies>\n</configuration>\n
Run Code Online (Sandbox Code Playgroud)\n\n

这应该会将许多插件拉入您的测试运行时,否则org.eclipse.e4.core.di这些插件可能不存在(例如,测试通常不\xe2\x80\x99t直接或间接依赖)。

\n\n

当然,只有当该org.eclipse.e4.rcp功能是您的目标平台的一部分时,上述方法才有效。

\n