Announcement Announcement Module
Collapse

Spring Dynamic Modules forum decommissioned in favor of Eclipse Gemini Blueprint

With the official first release of Eclipse Gemini Blueprint shipped, the migration of the Spring Dynamic Modules code base to the Eclipse Foundation, as part of the Gemini project, has been completed.

As such, this forum has been decommissioned in favour of the Eclipse Gemini forums.
See more
See less
Launching Junit tests from Eclipse Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Launching Junit tests from Eclipse

    Hi,
    I am trying to get a basic unit test to run via the Junit launcher within Eclipse. I've created a fragment using PDE that attached to a host plugin under test. Basic test class:

    Code:
    public class LearningSwitchTest extends AbstractConfigurableBundleCreatorTests {
        public void testOsgiPlatformStarts() throws Exception {
            System.out.println(bundleContext
                    .getProperty(Constants.FRAMEWORK_VENDOR));
            System.out.println(bundleContext
                    .getProperty(Constants.FRAMEWORK_VERSION));
            System.out.println(bundleContext
                    .getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT));
        }
    }
    I've added the following plugins to the list of "Automated Managemenf of Dependencies" inside the manifest:
    org.springframework.osgi.test
    org.springframework.test
    libraries.org.junit
    org.eclipse.osgi
    org.springframework.beans
    org.springframework.context
    org.springframework.core
    org.springframework.osgi.core
    com.springsource.org.objectweb.asm
    com.springsource.org.apache.commons.logging

    When I launch the test I see the following on the console:
    Code:
    Apr 15, 2010 11:54:50 PM org.springframework.osgi.test.AbstractOsgiTests logPlatformInfo
    INFO: Equinox OSGi Platform [3.5.2.R35x_v20100126] started
    Apr 15, 2010 11:54:50 PM org.springframework.osgi.test.provisioning.internal.LocalFileSystemMavenRepository init
    INFO: Local Maven2 repository used: [/home/test/.m2/repository]
    Apr 15, 2010 11:54:50 PM org.springframework.osgi.test.AbstractOsgiTests shutdownTest
    INFO: Shutting down OSGi platform
    and in the junit UI I see the following exception:
    Code:
    java.io.FileNotFoundException: /home/test/.m2/repository/org/aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsource.org.aopalliance-1.0.0.jar (No such file or directory)
    	at java.io.FileInputStream.open(Native Method)
    	at java.io.FileInputStream.<init>(FileInputStream.java:106)
    	at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:108)
    	at org.springframework.osgi.test.AbstractOsgiTests.installBundle(AbstractOsgiTests.java:323)
    	at org.springframework.osgi.test.AbstractOsgiTests.startup(AbstractOsgiTests.java:253)
    	at org.springframework.osgi.test.AbstractOsgiTests.prepareTestExecution(AbstractOsgiTests.java:374)
    	at org.springframework.osgi.test.AbstractOsgiTests.runBare(AbstractOsgiTests.java:203)
    	at org.springframework.osgi.test.AbstractOsgiTests$1.protect(AbstractOsgiTests.java:184)
    	at junit.framework.TestResult.runProtected(TestResult.java:128)
    	at org.springframework.osgi.test.AbstractOsgiTests.run(AbstractOsgiTests.java:181)
    	at junit.framework.TestSuite.runTest(TestSuite.java:232)
    	at junit.framework.TestSuite.run(TestSuite.java:227)
    	at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    I don't understand why its searching for a jar inside my maven repository. The target I am building for in Eclipse references external P2 update sites and one local directory. Does this test framework have any capability of working with Eclipse .target files? What is the best way to proceed to get the test up and running?

    Thanks,
    David

  • #2
    So I have spent a whole lot more time trying to understand how everything here works, and feel like I have a better, but slightly incomplete view of the system. I am now successfully using Spring DM inside my modules to wire things together, this is working great. I am also using Maven Tycho to build everything from the command line.

    What I would like to do is use Eclipse's built-in "JUnit Plug-in Test" launcher (also used by Maven) to handle launching the OSGI container and requisite plugins, which also injects its own plugin to run the JUnit tests in-container.

    The problems I am currently having are:
    -What is the best way to get ahold of the application context (to retrieve beans) from within the unit test executing inside the container?
    -After retrieving it, is it and the contained beans ready to go?

    I tried putting a bean that implements ApplicationContextAware into the beans list, that sets a static member of the containing class, and referencing that static instance from my unit tests, however this isn't working due to timing problems. I also tried forcing my fragment to be created synchronously via "Spring-Context: *;create-asynchronously:=false", but I'm not sure that it works with fragments and in any case didn't seem to help the situation.

    Thanks in advance.

    Comment


    • #3
      Hello,

      Originally posted by halcyon View Post
      So I have spent a whole lot more time trying to understand how everything here works, and feel like I have a better, but slightly incomplete view of the system. I am now successfully using Spring DM inside my modules to wire things together, this is working great. I am also using Maven Tycho to build everything from the command line.
      I would like to use the same kind of application: OSGi bundles based on springDM build with tycho.

      But I have problems creating spring based unit test running on tycho build.
      I have the current example structure:
      - a "core" bundle with an own SpringDM configuration
      - a "second" bundle depending on "core" with an own SpringDM configuration
      - a "second.tests" fragment containing the spring based unit tests for "second"
      The fragment has "required bundle" for all needed external test bundles (org.junit4, org.springframework.test, org.springframework.osgi.test, ...)

      The test classes look like this:
      Code:
      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration(locations = { "/META-INF/testcontext.xml" })
      public class ExampleTest {
      [...]
      When I try to run the tests from tycho or inside eclipse as "JUnit plugin test" I get ClassNotFoundExceptions for the classes used for beans in the testcontext.xml.

      Could you please tell me how you use spring based unit tests?

      Regards,
      Lars

      Comment


      • #4
        Hi Lars,
        I gave up on using Spring DM's test classes and decided to just roll my own. I have a class that extends TestCase, in its setup method it blocks waiting for an instance of the ApplicationContext to be set on a second class implementing ApplicationContextAware. Once it has a handle on the App context then it proceeds internally with its tests, this has worked well for me launching from both Eclipse and Tycho. You do have to be careful within Tycho that you explicitly list all bundles that are required that may not be listed as explicit imports within the bundles under test.

        Comment


        • #5
          Hello halcyon,

          Originally posted by halcyon View Post
          I gave up on using Spring DM's test classes and decided to just roll my own. I have a class that extends TestCase, in its setup method it blocks waiting for an instance of the ApplicationContext to be set on a second class implementing ApplicationContextAware. Once it has a handle on the App context then it proceeds internally with its tests, this has worked well for me launching from both Eclipse and Tycho. You do have to be careful within Tycho that you explicitly list all bundles that are required that may not be listed as explicit imports within the bundles under test.
          I tried to run a combination of spring 3.0.3, spring dm 2.0.0.M1, tycho 0.9.0-SNAPSHOT.
          To get tycho executing the test, I have to require bundle org.junit4. But this ends in an error with spring:

          !MESSAGE Package uses conflict: Require-Bundle: org.springframework.test; bundle-version="3.0.3"
          Did you manage this problem?

          Regards,
          Lars

          Comment


          • #6
            Hello,

            using the new junit4 (version 4.8) shipped with eclipse helios, the "Package uses conflict" has gone.

            But I don't get spring to be able to load the classes for the beans.

            I created a fragment, containing a TestClass and a SimpleBean in the same package. In the setup() method I can create a new instance of SimpleBean programmatic. If I try to load a spring context configured with a SimpleBean I get a ClassNotFoundException. Why can't spring load the same class?

            Regards,
            Lars

            Comment

            Working...
            X