Today we have a question from Edgar who asks if it's possible to deploy a contribution on per method basis? I like this question because the use of the Deploy annotation can be misleading. Here's why: You can put this annotation on a method and it won't do anything, which is deeply disturbing to me. That's because method annotations are never looked for in our JUnit runner (One day I'll have to fix the target of those annotations).
So if you cannot use the Deploy and LocalDeploy annotations on your method, the question is: How do you deploy bundles or contributions inside them? Well, the proper way to do this is to use the test harness you can inject in your test using the @Inject annotation.
Injection is one of the most important part of our test framework. But, it's not easy to know what you can/cannot inject. To understand this better, let's talk about Guice. It's the library used for injection. Know that you can only inject what you have manually bound to the injector. So if you can inject the test harness, it means someone has already bound it for you. This has happened in the RuntimeFeature.configure method (itself called by the FeatureRunner). In this method, every service deployed (which you can retrieve like this: Framework.getRuntime().getComponentManager().getServices()) are bound as well as the test harness. This is all you'll be able to inject during the test execution. To know what you can inject, look for the configure method of your test features.
Back to our first question, how to deploy bundles or contributions on a per method basis. Here's how: