|
Re: Did somebody use JUnit to test OSGi application? [message #100830 is a reply to message #100803] |
Thu, 01 November 2007 16:56 |
Eclipse User |
|
|
|
Originally posted by: Stefan-Isele.gmx.de
I also tried, but without success !
I made a TestCase,run it as a Plugin Test, but the bundles that includes
the tests is not started.
Because of that Activator.start is never called and I have no chance to
get a reference to the BundleContext that I nedd for the test.
For me looks like the Plugin Test Runner does not rvrn start OSGI !!
Please help !
Stefan Isele
David BY Chan schrieb:
> We can use JUnit to test our plug-in or standalone application, but I
> can't found an approach to test OSGi application though the development
> process of OSGi is similar to Plug-in.
>
> I found this article wrote by Peter Kriens:
>
> http://www.aqute.biz/Blog/2005-06-27
>
> , he said OSGi test tool was very different with JUnit.
>
> Has somebody a try?
|
|
|
Re: Did somebody use JUnit to test OSGi application? [message #101557 is a reply to message #100830] |
Thu, 15 November 2007 15:41 |
Christian Campo Messages: 597 Registered: July 2009 |
Senior Member |
|
|
Hi,
we are also starting to write testcases for OSGi based applications. One approach we have tried with success is to start
bundles that fullfill a certain pattern in the setUp method.
So a setUp method might look like this:
protected void setUp() throws Exception {
super.setUp();
startBundles("org\\.eclipse\\.equinox\\.cm.*", null);
startBundles("org\\.eclipse\\.equinox\\.log.*", null);
startBundles("org\\.eclipse\\.riena.*", null);
Then equinox Configuration Admin, Logging and the Riena projects are started. The startBundles method then looks like this:
public void startBundles(String truePattern, String falsePattern) throws BundleException {
if (truePattern == null) {
throw new UnsupportedOperationException("truePattern must be set");
}
if (falsePattern == null) {
falsePattern = "";
}
Pattern truePat = Pattern.compile(truePattern);
Pattern falsePat = Pattern.compile(falsePattern);
BundleContext context = Activator.getContext();
Bundle[] bundles = context.getBundles();
for (Bundle bundle : bundles) {
if (truePat.matcher(bundle.getSymbolicName()).matches()
&& !(falsePat.matcher(bundle.getSymbolicName()).matches())
&& (bundle.getState() == Bundle.RESOLVED || bundle.getState()==Bundle.STARTING) {
bundle.start();
}
}
}
So the setUp method adds bundles as dependencies for the testcase that have to be active in order for this testcase to
be successful. A problem in the above code is that you cannot start fragments. Currently we just avoid to include them
in our patterns. Otherwise you have to test in the startBundles method wether the bundle is a fragment. Well room for
improvment.
cheers
christian campo
Stefan Isele schrieb:
> I also tried, but without success !
> I made a TestCase,run it as a Plugin Test, but the bundles that includes
> the tests is not started.
> Because of that Activator.start is never called and I have no chance to
> get a reference to the BundleContext that I nedd for the test.
> For me looks like the Plugin Test Runner does not rvrn start OSGI !!
> Please help !
>
> Stefan Isele
>
> David BY Chan schrieb:
>> We can use JUnit to test our plug-in or standalone application, but I
>> can't found an approach to test OSGi application though the
>> development process of OSGi is similar to Plug-in.
>>
>> I found this article wrote by Peter Kriens:
>>
>> http://www.aqute.biz/Blog/2005-06-27
>>
>> , he said OSGi test tool was very different with JUnit.
>>
>> Has somebody a try?
>
|
|
|
Powered by
FUDForum. Page generated in 0.02951 seconds