I wonder if someone can point me to a good tutorial/sample/best practices about using JUnit4OSGI with Equinox as the OSGI container? I already downloaded JUnit4OSGI and started writing sample test cases, but what I'm looking for are answers for questions like:

1- How to structure the unit tests? put it in a separate bundle or each bundle should have its own unit tests?

2- How to run the unit tests using a maven plug-in? Or is there a better way?

3- How to run the unit tests during development as I understand there is a command line specific to Felix only.

Thanks.

有帮助吗?

解决方案

I cannot help with Junit4OSGi but I can offer an alternative that works with Maven. It has the following parts:

  • testRunner: A module that can run tests if they are registered as OSGi services
  • testRunner-junit4: Junit4 engine for the testrunner module
  • eosgi-maven-plugin: A maven plugin that can use the modules above and run the unit tests during integration-test phase in equinox, felix or a custom container
  • richconsole: A simple module that makes it possible to drop modules to the OSGi container. Together with the maven plugin they can be used to update maven dependencies in the container without restarting it

Testrunner itself does not really care what technology offered the OSGi service. It could be blueprint, DS, iPojo or whatever. It needs the followings:

  • eosgi.testId service property must be provided. This is a unique value
  • eosgi.testEngine service property must be provided. In case of JUnit this is junit4
  • In case of JUnit, the class/interface must be annotated with JUnit annotations. Beware that blueprint wraps the service objects (I do not know if iPojo does it as well) so you have to implement an interface in your class and annotate the functions in the interface instead of the class

I think the best place to start is the maven usage site. At the moment the osgi-liquibase-bundle project uses the most up-to-date versions. Without knowing what it does, it is a good example of configuration (project hierarchy and pom.xml configuration).

All the modules and the plugin is available at maven-central.

Update

A guide about the usage of the tools is available at http://cookbook.everit.org

Update 2016.12

There is an Eclipse plugin now that allows the user to start/stop/debug/upgrade the OSGi environments specified by eosgi-maven-plugin. The usage of the plugin has benefits over the usage of richconsole.

Cookbook will be updated soon to use the Eclipse plugin instead of richconsole.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top