Although Java projects and Java plug-in projects both use Java and JUnit to execute, plug-ins typically need to have access to them (provided by the runtime platform), which is only available if running in an OSGi or Eclipse environment.
com.packtpub.e4.junit.plugin
.PlatformTest
in the com.packtpub.e4.junit.plugin
package.testPlatform()
, which asserts that the Platform
is running:@Test public void test() { assertTrue(Platform.isRunning()); }
org.junit
to the required bundles.org.eclipse.core.runtime
is also added as a dependency.fail
(with an assertion error).Although the test code is exactly the same, the way in which the tests are run is slightly different. In the first instance, it uses the standard JUnit test runner, which executes the code in a standalone JVM. Since this doesn't have the full Eclipse runtime inside, the test fails.
The plug-in test is launched in a different way: a new Eclipse instance is created, the plug-in is exported and installed into the runtime, the various OSGi services that are needed to power Eclipse are brought up, and then the test runner executes the plugin in place.
As a result, running a plug-in test can add latency to the test process, because the platform has to be booted first. Sometimes, quick-tests are run as standalone Java tests, while integration tests run in the context of a full plug-in environment.
Code sections that depend on OSGi and Platform services need to be run as plug-in tests.