2

How can I package JUnit tests in OSGI bundle so that to run them with Apache Felix? Is there a standard implementation or some work around as to create separate bundle for JUnit tests and run them in activate method?

Edit: I've forgot to say that the project is created with Maven.

Update: Thank you for your answers. I've used junit4osgi framework and it's very useful.

John Smith
  • 233
  • 1
  • 2
  • 10

3 Answers3

1

If it's for running unit tests you may want to have a look at Pax Exam.

Philippe Marschall
  • 4,452
  • 1
  • 34
  • 52
1

You might want to take a look at how BndTools does this. It allows you to create integration OSGi tests which can be executed in an OSGi container.

Dan Gravell
  • 7,855
  • 7
  • 41
  • 64
  • It can do, read more here: http://stackoverflow.com/questions/10567325/working-with-maven-osgi-and-bndtools and http://njbartlett.name/2011/03/23/towards-maven-support-in-bndtools.html – Dan Gravell Sep 11 '12 at 13:11
1

The Apache Sling testing tools' org.apache.sling.junit.core bundle lets you run JUnit tests in an OSGi instance. It's part of the Sling project as it was created there, but should run on any OSGi environment without any Sling dependencies.

Bertrand Delacretaz
  • 6,100
  • 19
  • 24
  • Can you give me any simple example? There are too many documentation so that I can't track it. – John Smith Sep 11 '12 at 13:13
  • You can find two samples under http://svn.apache.org/repos/asf/sling/trunk/testing/samples - a sample tests bundle under sample-tests and a complete sample application including integration tests that use this technique under integration-tests. – Bertrand Delacretaz Sep 12 '12 at 07:44