maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Fiedler" <mfied...@wernervas.com>
Subject RE: [testng-users] TestNG from a custom Maven2 MOJO/plugin
Date Tue, 17 Jan 2006 02:07:02 GMT
Wow, thanks for the speedy reply!

 

Code:

                        try {

                                    getLog().info("testing class loading of 'org.testng.annotations.Test'");

                                    Class otat = Class.forName("org.testng.annotations.Test");

                                    getLog().info(otat.getClass().getName());

                                    getLog().info(otat.getCanonicalName());

                        } catch (ClassNotFoundException e) {

                                    getLog().error(e.getMessage());

                                    e.printStackTrace();

                        }

 

Result:

[INFO] testing class loading of 'org.testng.annotations.Test'

[INFO] java.lang.Class

[INFO] org.testng.annotations.Test

 

===============================================

Suite of Tests

Total tests run: 0, Failures: 0, Skips: 0

===============================================

 

[INFO] ----------------------------------------------------------------------------

[ERROR] FATAL ERROR

[INFO] ----------------------------------------------------------------------------

[INFO] Type org.testng.annotations.Test not present

[INFO] ----------------------------------------------------------------------------

[INFO] Trace

java.lang.TypeNotPresentException: Type org.testng.annotations.Test not present

        at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:98)

        at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)

        at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)

        at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:351)

        at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:175)

        at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)

...

 

 

Thank you, Michael

 

 

-----Original Message-----
From: cbeust@google.com [mailto:cbeust@google.com] 
Sent: Monday, January 16, 2006 7:53 PM
To: testng-users@googlegroups.com; Michael Fiedler
Cc: Maven Users List
Subject: Re: [testng-users] TestNG from a custom Maven2 MOJO/plugin

 

Hi Michael,

First of all, I just learned something today...  I had never heard of this TypeNotPresentException,
much less that it was in java.lang!  Its JavaDoc is interesting:

* Thrown when an application tries to access a type using a string
 * representing the type's name, but no definition for the type with
 * the specified name can be found.   This exception differs from
 * {@link ClassNotFoundException} in that <tt>ClassNotFoundException</tt> is a

 * checked exception, whereas this exception is unchecked.

So it *seems* to be similar to ClassNotFoundException, but since we're in the bowels of sun.reflect,
all the bets are off.  To tell the truth, I'm not quite sure what to make of this error without
having access to the source of CoreReflectionFactory. 

I'll do some digging, but in the meantime, here is a quick experiment:  can you do a Class.forName("org.testng.annotations.Test")?

-- 
Cedric



On 1/16/06, Michael Fiedler <mfiedler@wernervas.com> wrote:

Hi,

 

   I am writing a custom plugin for determining EMMA code coverage of TestNG tests.  I am
having trouble with the TestNG Test annotation.  TestNG is a dependency (see below).  The
TestNG version is 4.0, maven version is 2.0.1, jdk version is sun jdk1.5.

 

   It feels like a class loader type problem, but org.testng.annotations.Test is in the testng-4.0-jdk15.jar.
 Since the process was able to invoke the TestNG run method (and other classes), is this really
a class loader issue?

 

Thank you, Michael

 

 

Pom file:

<project>

            <modelVersion>4.0.0</modelVersion>

...

            <dependencies>

                        <dependency>

                                    <groupId>testNG</groupId>

                                    <artifactId>testng</artifactId>

                                    <version>4.0-jdk15</version>

                                    <scope>compile</scope>

                        </dependency>

...

 

 

code snippet:

...

                        TestNG testng = new TestNG(xmlSuite);

                        testng.setTestJar(jarFilename);

                        testng.setSourcePath(srcPath.getAbsolutePath() + ";" + testPath.getAbsolutePath());

                        testng.setOutputDirectory(metadataDir.getAbsolutePath() + "/testNG");

                        testng.setVerbose(1);

                        testng.setGroups("Preferred");

                        testng.run();

                        if(testng.hasFailure() && !testng.hasFailureWithinSuccessPercentage())
{

                                    throw new MojoFailureException("Testing failure occurance
is too high!");

                        }

...

 

 

stacktrace:

[INFO] ----------------------------------------------------------------------------

[ERROR] FATAL ERROR

[INFO] ----------------------------------------------------------------------------

[INFO] Type org.testng.annotations.Test not present

[INFO] ----------------------------------------------------------------------------

[INFO] Trace

java.lang.TypeNotPresentException: Type org.testng.annotations.Test not present

        at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:98)

        at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)

        at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)

        at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:351)

        at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:175)

        at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)

        at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)

        at java.lang.reflect.Method.declaredAnnotations(Method.java:676)

        at java.lang.reflect.Method.getDeclaredAnnotations(Method.java:669)

        at java.lang.reflect.AccessibleObject.getAnnotations(AccessibleObject.java:179)

        at org.testng.internal.jdk15.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:70)

        at org.testng.internal.jdk15.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:92)

        at org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.java:158)

        at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:49)

        at org.testng.TestRunner.initMethods(TestRunner.java:256)

        at org.testng.TestRunner.init(TestRunner.java:192)

        at org.testng.TestRunner.init(TestRunner.java:164)

        at org.testng.TestRunner.<init>(TestRunner.java:112)

        at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:325)

        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:160)

        at org.testng.SuiteRunner.run(SuiteRunner.java:126)

        at org.testng.TestNG.run(TestNG.java:292)

        at com.werner.osc.m2plugin.emma.Unit2.test2(Unit2.java:310)

        at com.werner.osc.m2plugin.emma.Unit2.execute(Unit2.java:82)

        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:432)

        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:530)

        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:485)

        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:455)

        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:303)

        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:270)

        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:139)

        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)

        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)

        at org.apache.maven.cli.MavenCli.main(MavenCli.java:249)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:585)

        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)

        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)

        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)

        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

Caused by: java.lang.ClassNotFoundException: org.testng.annotations.Test

        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)

        at java.security.AccessController.doPrivileged(Native Method)

        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)

        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)

        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

        at java.lang.Class.forName0(Native Method)

        at java.lang.Class.forName(Class.java:242)

        at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)

        ... 41 more

 

 




-- 
C├ędric


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message