OSGi Service Testing

What facilities existing in Bndtools 7.1 for testing OSGi services specifically? Any include service lifecycle testing or dynamics testing? Integration with SCR? How about Remote Services (multiple processes) testing?

Don’t have any experience with this. But maybe org.gecko.rest.jersey.tests from @juergen-albert and @MaHo has some clues.

In Bndtools you find launchpad, which helps starting and controlling frameworks for testing. Especially, if you want to test remote communication, this might help you. I never actually used it, so I can’t say much beyond that about it.

We usually use osgi test for testing, as it provides a wealth of useful tools for testing services.

Hi Juergen.

First, thanks for the input. I started through Testing With Launchpad

Using this test class

package org.eclipse.ecf.provider.etcd3.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import aQute.launchpad.Launchpad;
import aQute.launchpad.Launchpa>dBuilder;
import aQute.launchpad.Service;>
import aQute.launchpad.junit.LaunchpadRunner;
@RunWith(LaunchpadRunner.class)
public class TestMyCode extends junit.framework.TestCase {

LaunchpadBuilder builder = new >LaunchpadBuilder().runfw(“org.apache.felix.framework”).debug();

@Service
Launchpad launchpad;

@Test
public void testMyCode() throws Exception {
launchpad.report();
}
}

Which compiles just fine, but when run gives me this error:

ERROR: Bundle biz.aQute.tester.junit-platform [65] Error starting >file:/C:/Users/slewi/git/etcd3-discovery-provider/cnf/cache/7.1.0/bnd->cache/biz.aQute.tester.junit-platform/biz.aQute.tester.junit-platform-7.1.0.jar >(org.osgi.framework.BundleException: Unable to resolve biz.aQute.tester.junit-platform [65](R >65.0): missing requirement [biz.aQute.tester.junit-platform [65](R 65.0)] osgi.wiring.package; >(&(osgi.wiring.package=org.junit.platform.commons)(version>=1.3.0)(!(version>=2.0.0))) >Unresolved requirements: [[biz.aQute.tester.junit-platform [65](R 65.0)] osgi.wiring.package; >(&(osgi.wiring.package=org.junit.platform.commons)(version>=1.3.0)(!(version>=2.0.0)))])
org.osgi.framework.BundleException: Unable to resolve biz.aQute.tester.junit-platform [65]>(R 65.0): missing requirement [biz.aQute.tester.junit-platform [65](R 65.0)] >osgi.wiring.package; (&(osgi.wiring.package=org.junit.platform.commons)(version>=1.3.0)(!>(version>=2.0.0))) Unresolved requirements: [[biz.aQute.tester.junit-platform [65](R 65.0)] >osgi.wiring.package; (&(osgi.wiring.package=org.junit.platform.commons)(version>=1.3.0)(!>(version>=2.0.0)))]

with this line in the bnd file:

-tester: biz.aQute.tester.junit-platform

If I remove this line I get a similar but different error:

ERROR: Bundle biz.aQute.tester [65] Error starting file:/C:/Users/slewi/git/etcd3-discovery-provider/cnf/cache/7.1.0/bnd-cache/biz.aQute.tester/biz.aQute.tester-7.1.0.jar (org.osgi.framework.BundleException: Unable to resolve biz.aQute.tester [65](R 65.0): missing requirement [biz.aQute.tester [65](R 65.0)] osgi.wiring.package; (&(osgi.wiring.package=junit.framework)(version>=3.8.0)(!(version>=5.0.0))) Unresolved requirements: [[biz.aQute.tester [65](R 65.0)] osgi.wiring.package; (&(osgi.wiring.package=junit.framework)(version>=3.8.0)(!(version>=5.0.0)))])

This appears to me to be a matter of the junit.framework bundle (of new or older version) not being found, but I don’t easily know how to fix it according to bndtools.

Thanks for any advice.

For the case with -tester: biz.aQute.tester.junit-platform, it seems like junit-platform-commons bundle is missing on the runpath.

As I mentioned before, I have no experience with launchpad. I see that in the documentation, osgi.enroute.junit.wrapper is part of the testpath.

Thanks Juergen. I think I see what is wrong. I’m testing/using the (now default/only built in in bndtools 7.1) bndtools.workspace.min workspace template (with R8 builtin support). That workspace template does not have the repositories for biz.aQute.tester.junit-platform and dependencies.

Is there somewhere in the docs where I might find the up-to-date locations for those bundles and dependencies? I looked in the current bndtools docs under ‘testing’ and the repository in docs seems to be years old.

Thanks.

The dependencies in the osgi-test example should be fairly current. I don’t know about the ones in the docs and if we have some newer ones documented in the bnd doc.

Thanks. I’ve fussed around with adding junit5 pieces and it now looks like all the bundle resolution and classloading is happening (I’m starting things in Eclipse using the Bndtools run//debug config for Junit testing).

Now I’m getting a failure to find the actual test class…i.e.

elcome to Apache Felix Gogo

g! TEST org.eclipse.ecf.provider.etcd3.test.TestMyCode <<< ERROR: org.eclipse.ecf.provider.etcd3.test.TestMyCode not found by org.eclipse.ecf.provider.etcd3 [10]
java.lang.ClassNotFoundException: org.eclipse.ecf.provider.etcd3.test.TestMyCode not found by org.eclipse.ecf.provider.etcd3 [10]

TestMyCode is my test class (with the @Test method annotation and LaunchPad creating in it as shown above). Obviously there is some bnd workspace and/or project config that’s not right, but I can’t understand what. The .classpath does contain the package of the TestMyCode class, but the workspace template (minimal) that I started with to create the project did not have the ‘usual’ test config, so I suspect I’ve not configured the project correctly by hand.

Any diagnosis appreciated.

Hi @juergen-albert

I’ve consulted the documentation about LaunchPad. Frankly I find this documentation very confusing because it talks a lot about how the bndtooling works, and not nearly enough about how to configure the environment (at workspace and project level) to get to a working bndtools/junit/launchpad test environment.

My initial use case is for CI testing this etcd3-java provider: GitHub - ECF/etcd3-discovery-provider: ECF Remote Services Discovery Provider based upon Etcd

I’ve looked for example launchpad config (using R8 repos) and haven’t found one other than bndtools itself, which is far too complicated an environment to use for my etcd3 discovery provider.

FWIW, it would be very nice to have…as part of the bndtools.workspace.min workspace template, some project templates that have all the workspace and project config setup for Launchpad-based testing scenarios. If this already exists somewhere please point me at it.

If it doesn’t exist in 7.1, I would appreciate any pointers to workspace/projects that are a) based upon latest Launchpad code and infrastructure (e.g. R8) versions of supporting libraries and bundles (as is already the case in my etcd3 provider). I will attempt to copy the config.

Thanks.

Scott

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!