OSGi Service Testing

Dear @scottslewis , I pray that you are well.

I am sorry I have not responded sooner - I am not as able to be active on these forums any more., and I don’t have a lot of time to look at it.

To see launchpad in action, a good place to look might be in the Bndtools workspace itself - in the bndtools.tester.test project. It uses Launchpad exclusively under the hood.

However, for many cases, you do not need full Launchpad ability. Using a regular Bndtools-OSGi test and using the osgi-test library goes a long way to helping you run tests against services etc. For example, you can use the ServiceExtension to have a service injected into your test, and the test harness will take care of the boilerplate (eg, like waiting for a service to be present before continuing).

Generally speaking, a standard Bndtools OSGi test will run faster than a Launchpad test. This is because in Launchpad, a new framework is assembled and launched for every test method. This is useful if you want to (eg) test behaviour with the configuration of the framework under programmatic (and possibly dynamic) control, or generating synthetic bundles - however, usually you do not need this. OSGi tests, in contrast, launch the framework once at the beginning of the tests and then run all of the tests inside the context of that framework.

I also notice that your test case extends junit.framework.TestCase. That is JUnit 3. I would highly recommend upgrading to JUnit 5 (if you haven’t already), in which case you do not need to extend TestCase - just annotate your test messages with the @Test annotation from JUnit 5. I assume that you’ve done this because you wanted to use the Launchpad rule? If this is the case you still don’t need JUnit 3 - using the JUnit 4 @Test annotation is sufficient.

Finally, with OSGi testing, if you get the dependencies in the bndrun file right, you should be able to use the resolver to produce a runnable test launch (as you would for a normal application).

Sorry, these are a few, quick, semi-random thoughts - I hope it helps in some way!