The basing question:
How to do JUnit tests for RCP classes that create SWT GUI?
- The „Run As“ dialog of Eclipse offers a „Run as Plugin“ option which must be used if OSGI features are used in the test.
- If OSGI features are needed (e.g. an OSGI service is part of the game) than OSGI a BundleContext has to be set up. Read OSGI Component Testing (Integration testing / “black-box-testing”) and perhaps OSGI BundleContext.java.
If this is done, then a Bundle can be invoked/setup by FrameworkUtil.getBundle(AnyClassInTheTestPlugin.java)
OSGI BundleContext.java –> siehe Mindmap unten!
Setting up Eclipse like context for dependency injection:
If the class A has an annotation like
@Inject C c;
Then a class A can be retrieved that has an object of C already injected like that:
IEclipseContext context = EclipseContextFactory.create("test context"); context.set(C.class, new C(...)); A a = ContextInjectionFactory.make(A.class, context);
Problem while running on Linux Jenkins