NullPointerException in WorkbenchPage.busyShowView

I have a simple view, usually registered in my Eclipse plugin (4.5.2), and it works when I start an Eclipse instance using the plugin. 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"); } 

However, 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) 

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 error and a couple more, but I did not find anything, explaining why in Tycho this fails. And I could not find anything about how to fix it.

So what have I done wrong? How to fix it?

+6
source share
1 answer

My guess was that there was something missing in the test version of the time needed for the full-blown Eclipse toolkit and the added PDE, but Tycho doesnt. (By default, Tycho only adds the (transitive) dependencies of your eclipse-test-plugin to the test run time.)

Try adding the following to 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 a test runtime, which might otherwise be absent (for example, org.eclipse.e4.core.di , tests usually aren’t directly or indirectly dependent).

Of course, the above only works if the org.eclipse.e4.rcp function is part of your target platform.

+3
source

All Articles