felix-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Schulze <dean.w.schu...@gmail.com>
Subject Re: Loading a class from a different bundle dynamically
Date Fri, 12 Dec 2014 14:24:07 GMT
I don't think Pax Exam addresses my issue.

A little more explanation may help.

This system is driven by both external input and user input.  The
external input will be the same on each test run.  Controlling the
timing of the user input -- synchronizing it with the external input --
is the problem.  The typical unit test case is only driven by user input
so timing doesn't matter.  

Think of triggering a calculation where your inputs change constantly.
The calculation is different each time and in order to verify it I have
to trigger the calculation at exactly the same times on each test run.

My test classes have to monitor the internal state of my application to
synchronize with the external input in order to make them repeatable.
Without that synchronization automated testing will be impossible.

I don't want to put the test classes into the production bundles which
is why I'm trying to load them dynamically when the system is under
test.


On Fri, 2014-12-12 at 08:38 +0100, Achim Nierbeck wrote:
> Hi,
> 
> just one quick question/hint.
> You are aware of the Pax Exam Testframework?
> I think with it you are able to do what you are looking for.
> 
> regards, Achim
> 
> 
> 2014-12-12 6:41 GMT+01:00 Dean Schulze <dean.w.schulze@gmail.com>:
> 
> >
> > 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: users-unsubscribe@felix.apache.org
> > For additional commands, e-mail: users-help@felix.apache.org
> >
> >
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Mime
View raw message