<p>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.</p>

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

<p>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.</p>

<p>Is there a quick and easy way to test OSGi bundles?</p>

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

<p>EDIT2: Is there some framework that supports JUnit4?</p>

[{'answer_id': 74114, 'author': 'flicken', 'author_id': 12880, 'author_profile': 'https://Stackoverflow.com/users/12880', 'pm_score': 4, 'selected': True, 'text': '<p>Spring Dynamic Modules has excellent support for <a href="http://static.springframework.org/osgi/docs/current/reference/html/testing.html" rel="noreferrer"> testing OSGi bundles</a>.</p>\n'}, {'answer_id': 112077, 'author': 'Rafael Chaves', 'author_id': 20033, 'author_profile': 'https://Stackoverflow.com/users/20033', 'pm_score': 2, 'selected': False, 'text': '<p>Eclipse has a launch configuration type for running JUnit tests in the context of an Eclipse (i.e. OSGi) application:</p>\n\n<p><a href="http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tools/launchers/junit_launcher.htm" rel="nofollow noreferrer">http://help.eclipse.org/stable/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tools/launchers/junit_launcher.htm</a></p>\n'}, {'answer_id': 113217, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>If you need to test GUI components I\'ve found <a href="http://swtbot.org/" rel="nofollow noreferrer">SWTBot</a> gets the job done.</p>\n'}, {'answer_id': 152379, 'author': 'Toni Menzel', 'author_id': 1990802, 'author_profile': 'https://Stackoverflow.com/users/1990802', 'pm_score': 3, 'selected': False, 'text': '<p>There is a dedicated open source OSGi testing framework on OPS4J (ops4j.org) called <strong>Pax Drone</strong>.</p>\n\n<p>You might want to have a look at Pax Drone ([<a href="http://wiki.ops4j.org/confluence/x/KABo]" rel="noreferrer">http://wiki.ops4j.org/confluence/x/KABo]</a>) which enables you to use all Felix Versions as well as Equinox and Knopflerfish in your tests.</p>\n\n<p>Cheers,\nToni</p>\n'}, {'answer_id': 260261, 'author': 'user33790', 'author_id': 33790, 'author_profile': 'https://Stackoverflow.com/users/33790', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://code.google.com/p/treaty/" rel="nofollow noreferrer">Treaty</a> 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.</p>\n'}, {'answer_id': 7456623, 'author': 'Luca Geretti', 'author_id': 859596, 'author_profile': 'https://Stackoverflow.com/users/859596', 'pm_score': 4, 'selected': False, 'text': '<p>More recently, you should have a look at Pax Exam:\n<a href="http://team.ops4j.org/wiki/display/paxexam/Pax+Exam" rel="noreferrer">http://team.ops4j.org/wiki/display/paxexam/Pax+Exam</a></p>\n\n<p>This is the current effort at OPS4J related to testing.</p>\n'}, {'answer_id': 8128727, 'author': 'rescdsk', 'author_id': 88198, 'author_profile': 'https://Stackoverflow.com/users/88198', 'pm_score': 3, 'selected': False, 'text': '<p>Here are some tools not mentioned yet:</p>\n\n<ul>\n<li><p>I\'m using <a href="http://www.eclipse.org/tycho/" rel="noreferrer">Tycho</a>, 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.  <a href="http://wiki.eclipse.org/Tycho/Packaging_Types#eclipse-test-plugin" rel="noreferrer">Intro</a> and <a href="http://wiki.eclipse.org/Tycho/Reference_Card#Test_bundles" rel="noreferrer">further info</a>.  This is working quite well for me.</p></li>\n<li><p><a href="http://felix.apache.org/site/apache-felix-ipojo-junit4osgi-tutorial.html" rel="noreferrer">jUnit4OSGI</a> looks straightforward.  You make subclasses of OSGiTestCase, and you get methods like <code>getServiceReference()</code>, etc.</p></li>\n<li><p><a href="http://www.pluginbuilder.org/" rel="noreferrer">Pluginbuilder</a>, a headless build system for OSGi bundles / Eclipse plug-ins, has <a href="http://www.pluginbuilder.org/documentation/run-tests/" rel="noreferrer">a test-running framework</a> called <strong>Autotestsuite</strong>.  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.</p></li>\n<li><p>Another option is to start an instance of <strong>an OSGi container <em>within</em> your unit test</strong>, which you run directly, as explained <a href="http://www.talios.com/osgi_based_integration_testing_with_testng_and_apache_felix.htm" rel="noreferrer">here</a>. </p></li>\n<li><p>Here\'s someone who\'s written <strong>a small <a href="http://rcpquickstart.com/2008/06/12/running-unit-tests-for-rcp-and-osgi-applications/" rel="noreferrer">bundle test collector</a></strong>, which searches for JUnit (3) tests and runs them.</p></li>\n</ul>\n'}, {'answer_id': 10686725, 'author': 'Basy', 'author_id': 1408061, 'author_profile': 'https://Stackoverflow.com/users/1408061', 'pm_score': 1, 'selected': False, 'text': '<p>For unit tests use the EasyMock framework or create your own implementations of the required interfaces for testing .</p>\n'}, {'answer_id': 10846924, 'author': 'pooh', 'author_id': 1417114, 'author_profile': 'https://Stackoverflow.com/users/1417114', 'pm_score': 1, 'selected': False, 'text': '<p>The <a href="http://dz.prosyst.com/pdoc/mBS_SDK/um/runtime/osgi/docs/tee/index.html" rel="nofollow">ProSyst Test Execution Environment</a> is a useful test tool for OSGi bundles. It also supports JUnit tests as one of the possible test models. </p>\n'}, {'answer_id': 12805716, 'author': 'Tonny Madsen', 'author_id': 796559, 'author_profile': 'https://Stackoverflow.com/users/796559', 'pm_score': 0, 'selected': False, 'text': '<p>During the last couple of years <a href="http://eclipse.org/tycho/" rel="nofollow">Tycho</a> - 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...</p>\n'}, {'answer_id': 12886337, 'author': 'Balazs Zsoldos', 'author_id': 1354879, 'author_profile': 'https://Stackoverflow.com/users/1354879', 'pm_score': 1, 'selected': False, 'text': '<p>I think we met the same issue and we made our own solution. There are different parts of the solution:</p>\n\n<ul>\n<li>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.</li>\n<li>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.</li>\n<li>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. </li>\n</ul>\n\n<p>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).</p>\n\n<p>The whole solution is OpenSource. You can find a tutorial at <a href="http://cookbook.everit.org" rel="nofollow">http://cookbook.everit.org</a></p>\n'}, {'answer_id': 51754780, 'author': 'Gadi', 'author_id': 148397, 'author_profile': 'https://Stackoverflow.com/users/148397', 'pm_score': -1, 'selected': False, 'text': '<p>How about bnd-testing-maven-plugin?</p>\n\n<p>It allow running JUnit inside a running container like Felix or Equinox.\nIf you used the BNDTools for eclipse this is very similar but just maven withpout eclipse and without a UI.</p>\n\n<p><a href="https://github.com/bndtools/bnd/tree/master/maven/bnd-testing-maven-plugin" rel="nofollow noreferrer">https://github.com/bndtools/bnd/tree/master/maven/bnd-testing-maven-plugin</a></p>\n\n<p>also look at the effectiveosgi archetype for maven. This will give you a good starting point to build your project or just add tests.</p>\n\n<p><a href="https://github.com/effectiveosgi" rel="nofollow noreferrer">https://github.com/effectiveosgi</a></p>\n'}, {'answer_id': 57672850, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>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.</p>\n\n<p>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.</p>\n"}, {'answer_id': 66651654, 'author': 'haltunbay', 'author_id': 1171506, 'author_profile': 'https://Stackoverflow.com/users/1171506', 'pm_score': 0, 'selected': False, 'text': '<p>Along with others mentioned mockito is very handy to mock plugin dependencies(references etc). see <a href="https://www.baeldung.com/mockito-annotations" rel="nofollow noreferrer">https://www.baeldung.com/mockito-annotations</a></p>\n'}]
['https://Stackoverflow.com/questions/73881', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12828/']