Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [equinox-dev] Testing OSGI Bundles with JUnit

Hi Toni,

Thank you for your idea!

I have Reading about Pax Exam and  I am not clear about what exactly I have
to do for installing and using it in Equinox.

I would like to test a simple Bundle which uses Preference Service from
Equinox. I do not use neither Maven nor other containers, just Equinox v34.

As I have read in Pax Exam website, If I want to test my Bundle I should
create a Test Class similar to T1S2_HowToUseBundleContext example, I
thought, my Test Class should implements TestCase class but I do not see any
TestCase implementation in examples so I suppose that using "@RunWith(
JUnit4TestRunner.class )" it is enough. I asume either that I should also
include the next piece of code inside to fix Equinox as framework:

@Configuration
public Option[] configure() {
return options(
            equinox()
        );
}

Either I would have to fix @test in each method which I would like to test.

Finally I suppose that I would have to add pax-exam-junit.jar from
(http://repository.ops4j.org/maven2/org/ops4j/pax/exam/pax-exam-junit/0.5.0/
) and junit.jar from (JUnit website) to the classpath.

So if I am not wrong, the steps to test a Bundle in Equinox would be like as
shown below:

1-Include pax-exam-junit.jar and junit.jar in ClassPath
2-Create a new Bundle which will create a MyTestClass instance (with
“@RunWith( JUnit4TestRunner.class )" included.
3-Call to Preference Service from BundleContext object as the same way as I
did using the real Context in real bundles.
4- Launch Equinox with all the Bundles

And now, my questions are? HOw BundleContext can call to
bundleContext.getBundles method if it was defined as null in
T1S2_HowToUseBundleContext example?

Could I call for example
bundleContext.getService(“PreferenceServiceReference”)?


I either would like to ask about the results, how do I get test results? Is
it possible to use junit.swingui.TestRunner in order to get results as a
visual interface?

Thank you in advance

David

-----Mensaje original-----
De: equinox-dev-bounces@xxxxxxxxxxx [mailto:equinox-dev-bounces@xxxxxxxxxxx]
En nombre de Toni Menzel
Enviado el: jueves, 14 de mayo de 2009 12:06
Para: Equinox development mailing list
Asunto: Re: [equinox-dev] Testing OSGI Bundles with JUnit

Have you had a look at pax exam
(http://wiki.ops4j.org/display/paxexam/Pax+Exam) ?

It actually lets you write Junit Tests in OSGi Framework independent way.
You finally wrap your test in a test probe bundle (built on the fly),
start your target framework (equinox in this case), provision it with
you setup (extra bundles), and thats about it.

IF you use PDE (because you pointed to the fact you are using eclipse
a couple of times):
Without external means like maven you probably end up re-specifiying
all your dependencies again just for test setup.

Tell us if you do or not as it might help us a lot to get you started
with pax exam.

Finally, in exam you end up inside an isolated vm process running just
your test vm with your test framework
(Equinox,Felix,Knopflerfish,Concierge, all recent versions at you
fingertipps) exactly as specified. From there you (currently) get the
(real!) bundleContext from where you probably get any service you
want.

Toni




On 5/14/09, David Conde <dconde@xxxxxxxx> wrote:
> Hi everyone,
>
>
>
> I am trying to do test cases for OSGI Bundles in Equinox, using Eclipse. I
> found the problem when I tried to model BundleContext and services like
> Preference Services, which are complex objects. I read about how I could
> solve this problem and I found some libraries from Spring Framework which
> use “mocks” to test BundleContext, but I am not sure if these ones
provided
> special Services likes Preference services. So, my question is , is there
> any library with mocks to simulate BundleContext and other complex Equinox
> classes? Is there any library provided by Equinox?
>
>
>
> Thank you in advance
>
>
>
>
>
> --
>
> David Conde Baena
>
>
> CITIC
> Centro Andaluz de Innovación y Tecnologías de la Información y las
> Comunicaciones
> Edificio CITIC, C/ Marie Curie, 6
> Parque Tecnológico de Andalucía
> 29590 - Campanillas (MÁLAGA)
>
> Tfno.: +34 952028610
> Fax: +34 951231029
>  <mailto:usuario@xxxxxxxx> Email: dconde@xxxxxxxx
>  <http://www.citic.es/> Web: www.citic.es
>
>
>
>
>
>


-- 
Toni Menzel
Independent Software Developer - Looking for new projects!
Professional Profile: http://www.osgify.com
Blog: tonitcom.blogspot.com
toni@xxxxxxxxxxxxxxx
http://www.ops4j.org     - New Energy for OSS Communities - Open
Participation Software.
_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev



Back to the top