PDA

View Full Version : Testing in Spring DM


rico
May 14th, 2008, 10:39 PM
I am writing an integration test using Spring DM and I still climbing the learning curve :-).
I noticed that when I write a test, part of it is executed outside of the OSGi bundle (e.g. getTestBundlesNames()), while other methods (e.g. the test methods) are executed inside the OSGi container. The problem is that I still have to import everything in the container, even those packages that I only use outside of the container. I was wondering if there is a better way to separate the two stages...

In my case another solution to the same problem would come from really splitting framework bundles from test bundles (right now it's just a logical distinction and they are merged and started at the same time in the container). Basically I want to load some bundles (the framework) whose services I am then going to leverage to prepare my test execution (e.g. I want to start the OBR service, so that I can get my dependencies from there). Is there a way of cleanly doing it? I couldn't find a good hook for that.

Thanks for your ideas,
-rico

Costin Leau
May 15th, 2008, 03:25 AM
All packages used by your testing class have to be imported inside OSGi, that's correct since in JUnit 3, the entire execution is monolithic. The test runner delegates the actual execution to the test case and splitting them up is awkward and cumbersome in my opinion.
You can always however, extract the common functionality into a separate bundle, install that one alone and then use services to reuse its functionality.
You can create a base class that installs the common bundles either though getTestFrameworkBundlesNames()/getTestingFrameworkBundlesConfiguration()
or getTestBundlesNames().
Cheers

rico
May 15th, 2008, 02:45 PM
As you mentioned it, is there a plan to support JUnit 4 and TestNG? :-)

I liked the idea of the common bundle, I was actually heading that direction.
That's the problem that I was mentioning before though. The framework bundles are actually loaded together with the test bundles. If this were done in two stages I would be able to use the framework bundle to prepare the environment, but currently that is not possible.
Please correct me if I am mistaking.

Thanks for your help.
-rico

Costin Leau
May 15th, 2008, 02:56 PM
As you mentioned it, is there a plan to support JUnit 4 and TestNG? :-)


Yes, see Spring-DM issue tracker.


I liked the idea of the common bundle, I was actually heading that direction.
That's the problem that I was mentioning before though. The framework bundles are actually loaded together with the test bundles. If this were done in two stages I would be able to use the framework bundle to prepare the environment, but currently that is not possible.
Please correct me if I am mistaking.

You are mistaking - the framework bundles are loaded first and then the testing bundles. The bundles are started in the order given by the user - in your case you could place your common bundle first.
However, note that in general it is not advised to reply on ordering - it's best to deal with this inside your services.

janblankenhorn
Jun 3rd, 2008, 06:12 AM
Yes, see Spring-DM issue tracker.


You are mistaking - the framework bundles are loaded first and then the testing bundles. The bundles are started in the order given by the user - in your case you could place your common bundle first.
However, note that in general it is not advised to reply on ordering - it's best to deal with this inside your services.

This sounds interesting, but I still don't get it completely. Could you please describe a little bit more detailled, which jobs are done in which place?

Thanks a lot !

Costin Leau
Jun 3rd, 2008, 10:31 AM
I'm not sure what you mean by 'jobs' but see the reference documentation (the chapter on testing framework/integration testing) and the javadocs for AbstractConfigurableBundleCreatorTests. Basically you need to override getTestBundlesNames (or getTestBundles) to provide the user bundles.

janblankenhorn
Jun 4th, 2008, 05:13 AM
sorry for my bad question :)

i wanted to know a little bit more about the stuff to put into a "common bundle" for testing.
You described above that this could be than provided as a service to use in other tests, I just don't yet understand how to exactly do this.

regards

Costin Leau
Jun 5th, 2008, 01:26 AM
What exactly are you trying to do? In my case, I've rarely ran into cases where a 'common' bundle was needed. It depends on the setup but in practice, for Spring-DM integration tests, the testing framework was setting up the infrastructure and the tests were/are executed mainly by using the OSGi service registry along with the instantiated bean factory.
The two common parts (service registry + bean factory) are already there so there wasn't anything else to add as for the utils - they were part of Spring-DM and Spring which were already installed.

Costin Leau
Jun 5th, 2008, 01:27 AM
By the way, check out the Spring-DM screencast on integration testing - it starts from zero and shows how the testing framework works:
http://www.springframework.org/osgi/demos