I have an OSGI app consisting of several bundles.  In order to do
functional testing I want to dynamically load test case classes when the
-Dtest.class.name=MyTestClass property is set.  I want to keep the test
classes in their own bundle to make it easy to exclude them from the
production binary.  The only test artifact that will be in the
production code bundles will be an interface that the test classes
implement.

The test bundle depends on the production bundles to access the test
interface and because the test classes also use other classes in the
production bundles.  The test classes themselves are POJOs.  They are
not Serice or Component classes.  I only want to load them when the
test.class.name property is set so I don't want Felix injecting them.

I try to load the test class 

public class MyTestClass implements MyTestClassI {
    ....
}

from the production bundle code like this

MyTestClassI myTestClass;

....

//      Inside the @Activate method
String testClassName = System.getProperty("test.class.name");
if (testClassName != null) {
        
        Class c = Class.forName(testClassName);
        myTestClass = c.newInstance();
}

This gives a ClassNotFoundException.

The recommended solution that I've seen to this problem is to use the
Bundle.loadClass() method, but I haven't seen any example code that
actually does this.  I would have to get the test Bundle first and I
haven't been able to find out how to do this.

If anyone knows of example code to do dynamic class loading in Felix I
would appreciate a link to it.  If this kind of dynamic loading can only
be done form the gogo shell I could live with that since this would only
be done by the development and test teams.

Thanks.

Dean




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to