Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Include Page
FELIX:apache-felix-ipojo-headerFELIX:
apache-felix-ipojo-header

...

Developing OSGi tests can be definitely boring. First, testing is generally not a very exciting experience, but imagine if you have to handle all the OSGi issues in your tests... Don't worry junit4osgi provides methods allowing to interact easily with OSGi!

Div
classtoc
Table of Contents
maxLevel4
minLevel2

...

OSGi methods

junit4osgi test case extends the OSGiTestCase class. This class provides useful methods allowing to find services, get them, get the PackageAdmin service... The description of these methods can be found afterwardsafterward.

The most part of the methods are available statically and non-statically. Static methods require a Bundle. Non static methods use the current bundle context, and track get services to release them when the test is done. So, we advise you to use the non-static methods. Static methods just allow you to check that a specific bundle can access to services / resources.

...

So, for example, if you write iPOJO tests, you can use the iPOJO helper providing a lot of utility function functions simplifying the development of tests.

Code Block
java
java
public class MyTest extends OSGiTestCase {
	ComponentInstance fooProvider1, fooProvider2;
	
	IPOJOHelper helper; // Helper object

    public void setUp() {
        helper = new IPOJOHelper(this);	// Create the object.	
	String type2 = "PS-FooProviderType";
	
	fooProvider1 = helper.createComponentInstance(type2, p3);
        fooProvider2 = helper.createComponentInstance(type2, "FooProvider-4");
    }
	
	    public void tearDown() {
		helper.dispose(); // Dispose it, instances will be disposed too.
    }

You can also implements your own helper (for specific purpose) by just implementing the Helper interface.

Include Page
FELIX:apache-felix-ipojo-footerFELIX:
apache-felix-ipojo-footer