The RuntimeFeature annotation does not currently allow to stop and start the runtime on each method (like the CoreFeature Granularity.Method setting).
This makes it difficult to test runtime components overrides in tests (also because deployment API is not good for it).
Current workaround implies doing something like:
@RunWith(FeaturesRunner.class) @Features({ TransactionalFeature.class, RuntimeFeature.class }) @Deploy({ "xxx" }) @LocalDeploy({ "xxx"}) public class MyTest { @Inject protected RuntimeHarness harness; @Test public void testOverride() throws Exception { assertEquals(...); String contrib = "OSGI-INF/my-test-override-contrib.xml"; URL url = getClass().getClassLoader().getResource(contrib); RuntimeContext ctx = null; try { ctx = harness.deployTestContrib("my.current.bundle", url); assertEquals(...); } finally { if (ctx != null) { // make sure initial state is restored for other tests in same class ctx.destroy(); } } } }
A better implementation (that would also not produce strange behaviour when the undeploy feature is buggy on tested component) would be:
@RunWith(FeaturesRunner.class) @Features({ TransactionalFeature.class, RuntimeFeature.class }) @Deploy({ "xxx" }) @LocalDeploy({ "xxx"}) @SomeAnnotationPickedUpByRuntimeFeature(cleanup = Granularity.METHOD) public class MyTest { @Inject protected RuntimeHarness harness; @Test public void testOverride() throws Exception { assertEquals(...); String contrib = "OSGI-INF/my-test-override-contrib.xml"; URL url = getClass().getClassLoader().getResource(contrib); harness.deployTestContrib("my.current.bundle", url); assertEquals(...); } }
- is required by
-
NXP-16119 Fix target platforms unit tests
- Resolved