Results 1 to 9 of 9

Thread: Testing in Spring DM

  1. #1
    Join Date
    Jan 2008
    Posts
    9

    Default Testing in Spring DM

    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
    Last edited by rico; May 14th, 2008 at 09:42 PM.

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Jan 2008
    Posts
    9

    Default

    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
    Last edited by rico; May 15th, 2008 at 01:49 PM.

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Quote Originally Posted by rico View Post
    As you mentioned it, is there a plan to support JUnit 4 and TestNG? :-)
    Yes, see Spring-DM issue tracker.

    Quote Originally Posted by rico View Post
    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5

    Default

    Quote Originally Posted by Costin Leau View Post
    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 !

  6. #6
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  7. #7

    Default

    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

  8. #8
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  9. #9
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •