I have a simple view registered normally in my Eclipse plug-in (4.5.2), and it works when I start an Eclipse instance with the plug-in. It still works in the corresponding test case, which has the following method:
@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");
}
Yet when I run the same test with Tycho (0.22, 0.24 or 0.25), I get the following exception:
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)
The Tycho code is simple:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
<providerHint>junit4</providerHint>
<useUIHarness>true</useUIHarness>
</configuration>
</plugin>
I found this bug and a couple more, but I found nothing explaining why it would only fail in Tycho. And I couldn't find anything on how to fix this.
So what did I do wrong? How do I fix it?
My guess would be that something is missing in your test runtime that’s required by the full-blown Eclipse workbench and which PDE adds, but Tycho doesn’t. (By default, Tycho only adds the (transitive) dependencies of your eclipse-test-plugin
to the test runtime.)
Try adding the following to your tycho-surefire-plugin
execution:
<configuration>
<!-- ... ->
<dependencies>
<dependency>
<artifactId>org.eclipse.e4.rcp</artifactId>
<type>eclipse-feature</type>
</dependency>
</dependencies>
</configuration>
This should pull a lot of plugins into your test runtime that may not be present otherwise (like org.eclipse.e4.core.di
, which tests normally don’t depend on directly or indirectly).
Of course, the above only works if the org.eclipse.e4.rcp
feature is part of your target platform.