Results 1 to 3 of 3

Thread: spring based unit test build with tycho?

  1. #1
    Join Date
    Feb 2009
    Posts
    16

    Default spring based unit test build with tycho?

    Hello,

    I would like to migrate the build of a Spring Dynamic Modules project to maven3 with sonatype tycho.

    The project contains multiple OSGi bundles. Within every bundle exists a fragment with unit test classes and spring test configurations. With tycho, now these tests are failing.

    The test classes look like this:
    Code:
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = { "/META-INF/context.xml" })
    public class ExampleTest {
    [...]
    Trying to run the tests with maven + tycho, I get this error:

    Running ExampleTest
    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
    <<< FAILURE!
    initializationError(ExampleTest) Time elapsed: 0 sec <<< ERROR!
    java.lang.TypeNotPresentException: Type [unknown] not present
    at sun.reflect.annotation.TypeNotPresentExceptionProx y.generateException(TypeNotPresentExceptionProxy.j ava:27)
    at sun.reflect.annotation.AnnotationInvocationHandler .invoke(AnnotationInvocationHandler.java:56)
    at $Proxy4.value(Unknown Source)
    at org.junit.internal.builders.AnnotatedBuilder.runne rForClass(AnnotatedBuilder.java:24)
    at org.junit.runners.model.RunnerBuilder.safeRunnerFo rClass(RunnerBuilder.java:57)
    at org.junit.internal.builders.AllDefaultPossibilitie sBuilder.runnerForClass(AllDefaultPossibilitiesBui lder.java:29)
    at org.junit.runners.model.RunnerBuilder.safeRunnerFo rClass(RunnerBuilder.java:57)
    at org.junit.internal.requests.ClassRequest.getRunner (ClassRequest.java:24)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.<in it>(JUnit4TestSet.java:45)
    at org.apache.maven.surefire.junit4.JUnit4DirectoryTe stSuite.createTestSet(JUnit4DirectoryTestSuite.jav a:56)
    at org.apache.maven.surefire.suite.AbstractDirectoryT estSuite.locateTestSets(AbstractDirectoryTestSuite .java:96)
    at org.apache.maven.surefire.Surefire.createSuiteFrom Definition(Surefire.java:209)
    at org.apache.maven.surefire.Surefire.run(Surefire.ja va:156)
    at org.codehaus.tycho.surefire.osgibooter.OsgiSurefir eBooter.run(OsgiSurefireBooter.java:75)
    at org.codehaus.tycho.surefire.osgibooter.HeadlessTes tApplication.run(HeadlessTestApplication.java:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.internal.app.EclipseAppContain er.callMethodWithException(EclipseAppContainer.jav a:574)
    at org.eclipse.equinox.internal.app.EclipseAppHandle. run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseA ppLauncher.runApplication(EclipseAppLauncher.java: 110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseA ppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.ru n(EclipseStarter.java:368)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.ru n(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework( Main.java:559)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.ja va:514)
    at org.eclipse.equinox.launcher.Main.run(Main.java:13 11)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1 287)
    Caused by: java.lang.NoClassDefFoundError:
    org/junit/runners/BlockJUnit4ClassRunner
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader. java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :616)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.defineClass(DefaultClassLoader.java:183)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.defineClass(ClasspathManager.java:576)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.findClassImpl(ClasspathManager.java:546)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.findLocalClassImpl(ClasspathManager.java:477)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.findLocalClass_LockClassLoader(ClasspathManager .java:465)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManag er.findLocalClass(ClasspathManager.java:445)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.findLocalClass(DefaultClassLoader.java:211)
    at org.eclipse.osgi.internal.loader.BundleLoader.find LocalClass(BundleLoader.java:381)
    at org.eclipse.osgi.internal.loader.SingleSourcePacka ge.loadClass(SingleSourcePackage.java:33)
    at org.eclipse.osgi.internal.loader.BundleLoader.find ClassInternal(BundleLoader.java:454)
    at org.eclipse.osgi.internal.loader.BundleLoader.find Class(BundleLoader.java:410)
    at org.eclipse.osgi.internal.loader.BundleLoader.find Class(BundleLoader.java:398)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.loadClass(DefaultClassLoader.java:105)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at sun.reflect.generics.factory.CoreReflectionFactory .makeNamedType(CoreReflectionFactory.java:95)
    at sun.reflect.generics.visitor.Reifier.visitClassTyp eSignature(Reifier.java:107)
    at sun.reflect.generics.tree.ClassTypeSignature.accep t(ClassTypeSignature.java:31)
    at sun.reflect.annotation.AnnotationParser.parseSig(A nnotationParser.java:370)
    at sun.reflect.annotation.AnnotationParser.parseClass Value(AnnotationParser.java:351)
    at sun.reflect.annotation.AnnotationParser.parseMembe rValue(AnnotationParser.java:280)
    at sun.reflect.annotation.AnnotationParser.parseAnnot ation(AnnotationParser.java:222)
    at sun.reflect.annotation.AnnotationParser.parseAnnot ations2(AnnotationParser.java:69)
    at sun.reflect.annotation.AnnotationParser.parseAnnot ations(AnnotationParser.java:52)
    at java.lang.Class.initAnnotationsIfNecessary(Class.j ava:3070)
    at java.lang.Class.getAnnotation(Class.java:3029)
    at org.junit.internal.builders.IgnoredBuilder.runnerF orClass(IgnoredBuilder.java:13)
    ... 29 more
    Caused by: java.lang.ClassNotFoundException:
    org.junit.runners.BlockJUnit4ClassRunner
    at org.eclipse.osgi.internal.loader.BundleLoader.find ClassInternal(BundleLoader.java:494)
    at org.eclipse.osgi.internal.loader.BundleLoader.find Class(BundleLoader.java:410)
    at org.eclipse.osgi.internal.loader.BundleLoader.find Class(BundleLoader.java:398)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClass Loader.loadClass(DefaultClassLoader.java:105)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    ... 60 more
    Where is my mistake? Is there a solution, how I can run spring based unit tests with tycho?

    Regards,
    Lars

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Judging from the stacktrace you are using a wrong version (< 4.7) of JUnit... Make sure you use a 4.7 version of JUnit and also configure other plugins to use this... Else you will/might run into these issues.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2009
    Posts
    16

    Default

    Hello Marten

    Quote Originally Posted by Marten Deinum View Post
    Judging from the stacktrace you are using a wrong version (< 4.7) of JUnit... Make sure you use a 4.7 version of JUnit and also configure other plugins to use this... Else you will/might run into these issues.
    Thank you for your hint. I now use the bundle org.junit4 version 4.8.1 from the helios update.
    But now I get NoClassFoundExceptions for the bean declared in the spring configuration inside the tests fragment.


    Lets say I have a "core" bundle and a depending "second" bundle.

    There is also a "second.tests" fragment containing spring based unit tests. The spring context has beans with classes from the "core" bundle.

    Do I have to extend AbstractConfigurableBundleCreatorTests as described in the SpringDM Reference Guide or is it sufficient just to use the "core" bundle as required bundle of the "second" bundle?

    Sonatype Tycho brings its own maven-osgi-test-plugin for running unit tests in an osgi environment. Is someone else here using sonatype tycho with spring DM and could tell me how to setup the unit tests?

    Regards,
    Lars

Posting Permissions

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