16

Currently, I am working on a new version control system as part of a final year project at University. The idea is to make it highly adaptable and pluggable.

We're using the OSGi framework (Equinox implementation) to manage our plug ins. My problem is that I can't find a simple & easy to use method for testing OSGi bundles.

Currently, I have to build the bundle using Maven and then execute a test harness. I'm looking for something like the JUnit test runner for Eclipse, as it will save me a bunch of time.

Is there a quick and easy way to test OSGi bundles?

EDIT: I don't need something to test Eclipse plug ins or GUI components, just OSGi bundles.

EDIT2: Is there some framework that supports JUnit4?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
fluffels
  • 4,051
  • 7
  • 35
  • 53

14 Answers14

12

More recently, you should have a look at Pax Exam: http://team.ops4j.org/wiki/display/paxexam/Pax+Exam

This is the current effort at OPS4J related to testing.

Luca Geretti
  • 10,206
  • 7
  • 48
  • 58
  • 3
    Their site is down a lot. GitHub sites: [Pax Exam 1](https://github.com/ops4j/org.ops4j.pax.exam1), [Pax Exam 2](https://github.com/tonit/exxam), [Tutorial for Pax Exam 2](https://github.com/tonit/Learn-PaxExam) – rescdsk Nov 29 '11 at 20:11
7

Here are some tools not mentioned yet:

  • I'm using Tycho, which is a tool for using Maven to build Eclipse plugins. If you create tests inside their own plug-ins, or plug-in fragments, Tycho can run each set of tests inside its own OSGi instance, with all its required dependencies. Intro and further info. This is working quite well for me.

  • jUnit4OSGI looks straightforward. You make subclasses of OSGiTestCase, and you get methods like getServiceReference(), etc.

  • Pluginbuilder, a headless build system for OSGi bundles / Eclipse plug-ins, has a test-running framework called Autotestsuite. It runs the tests in the context of the OSGi environment, after the build step. But, it doesn't seem to have been maintained for several years. I think that many Eclipse projects are migrating from Pluginbuilder to Tycho.

  • Another option is to start an instance of an OSGi container within your unit test, which you run directly, as explained here.

  • Here's someone who's written a small bundle test collector, which searches for JUnit (3) tests and runs them.

rescdsk
  • 8,739
  • 4
  • 36
  • 32
6

There is a dedicated open source OSGi testing framework on OPS4J (ops4j.org) called Pax Drone.

You might want to have a look at Pax Drone ([http://wiki.ops4j.org/confluence/x/KABo]) which enables you to use all Felix Versions as well as Equinox and Knopflerfish in your tests.

Cheers, Toni

Toni Menzel
  • 764
  • 3
  • 10
6

Spring Dynamic Modules has excellent support for testing OSGi bundles.

flicken
  • 15,443
  • 4
  • 29
  • 29
  • Using SpringDM, I just get this: junit.framework.AssertionFailedError: Exception in constructor: testOSGiStart (java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory Any ideas? I've added commons-logging to the build path, btw. – fluffels Oct 06 '08 at 11:38
  • Also, SpringDM doesn't seem to support JUnit4, is this correct? – fluffels Oct 06 '08 at 11:39
  • NoClassDefFoundError occures when jvm cannot find .class file during runtime, although it was available during compile time. So it is not a fault of SpringDM, u just need to build ur project again. If u are using maven build through maven, or if ur eclipse has setting of auto build is enabled just make a little change in ur java file and save it. U will not get this error after that. – Sandeep Sep 06 '16 at 06:43
3

Eclipse has a launch configuration type for running JUnit tests in the context of an Eclipse (i.e. OSGi) application:

http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tools/launchers/junit_launcher.htm

Rafael Chaves
  • 553
  • 4
  • 12
1

For unit tests use the EasyMock framework or create your own implementations of the required interfaces for testing .

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
Basy
  • 11
  • 1
1

The ProSyst Test Execution Environment is a useful test tool for OSGi bundles. It also supports JUnit tests as one of the possible test models.

pooh
  • 652
  • 3
  • 2
1

If you need to test GUI components I've found SWTBot gets the job done.

1

I think we met the same issue and we made our own solution. There are different parts of the solution:

  • A junit4runner that catches all OSGi services that has a special property defined. It runs these caught services with JUnit4 engine. JUnit annotations should be placed into interfaces that the services implement.
  • A maven plugin that starts an OSGi framework (a custom framework can be created as maven dependency) and runs the unit tests inside the integration-test maven lifecycle.
  • A deployer OSGi bundle. If this is dropped into your OSGi container a simple always-on-top window will be opened where you can drop your project folders (from total commander or from eclipse). This will then redeploy that bundle.

With the tools you can do TDD and have the written tests always run inside the maven integration-phase as well. It is recommended to use eclipse with m2e and maven-bundle-plugin as in this case the target/classes/META-INF/MANIFEST.MF is regenerated as soon as you save a class in your source so you can drag the project and drop to the deployer window. The OSGi bundles you develop do not have to have any special feature (like being an eclipse plugin or something).

The whole solution is OpenSource. You can find a tutorial at http://cookbook.everit.org

Balazs Zsoldos
  • 6,036
  • 2
  • 23
  • 31
1

Treaty is a contract(testing) framework that is pretty academic but has some nice ideas. There are papers that are published on it, and the people currently working on improving it.

user33790
  • 91
  • 1
  • 3
0

During the last couple of years Tycho - a new Maven based build system for OSGi - has become rather popular among the Eclipse Foundation. This framework also includes method to use Maven Surefire to test OSGi bundles in separate testbeds...

Tonny Madsen
  • 12,628
  • 4
  • 31
  • 70
0

There are many ways to test OSGi components, I suppose. One way of doing the testing is to use Robot Framework. What I've done is made my tests with Robot Framework and have the remote libraries either installed in OSGi or have them talk to OSGi-test components through sockets and robot would talk to these modules and run tests through them.

So, basically your OSGi-modules should have interfaces that do something and produce some output. So, in my setup I had a test components that would make service calls to the actual OSGi-component and then there would be a listening-service that would catch the events/service calls (made by the module under test) and those results could be asked by the robot. So basically this way you can split a massive system in small components and have the system run in production/production like enviroment and have it tested automatically on component level or have some of the real components be tested in unison.

0

Along with others mentioned mockito is very handy to mock plugin dependencies(references etc). see https://www.baeldung.com/mockito-annotations

haltunbay
  • 615
  • 6
  • 15
-1

How about bnd-testing-maven-plugin?

It allow running JUnit inside a running container like Felix or Equinox. If you used the BNDTools for eclipse this is very similar but just maven withpout eclipse and without a UI.

https://github.com/bndtools/bnd/tree/master/maven/bnd-testing-maven-plugin

also look at the effectiveosgi archetype for maven. This will give you a good starting point to build your project or just add tests.

https://github.com/effectiveosgi

Gadi
  • 1,539
  • 22
  • 37
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – Auden Young Aug 08 '18 at 20:05