ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Andrew.Beac...@nokia.com>
Subject Issue with JUnit, forking, & classloading?
Date Tue, 25 Jun 2002 15:50:24 GMT
Ant-Users,

I am experiencing an interesting problem when using Ant 1.5Beta3 and 
JUnit3.7 (on Windows2000).

I have a <junit> task that runs my unit tests.  I have chosen to set 
fork="no" so that the tests run a little faster (I can set fork="yes" 
for the nightly build).

I have set up 2 formatters one of type="xml" and one of type "plain".
Both of these are reporting to files.

My unit tests have import statements including some XML (SAX) classes, 
that should be loaded from j2ee.jar (from J2EE1.3.0, required by our app 
server) that is in my test classpath.

What seems to be happening is that JUnit is correctly finding and 
loading the classes from j2ee.jar, but when the task's XML formatter object 
tries to start writing it's output it's using the classes loaded from 
j2ee.jar rather than the xml-apis/xalan jars in the Ant lib, and so I 
get a java.lang.LinkageError error.

If I set fork="yes" then I don't have this issue.  But, this all worked 
fine with Ant1.4.1, so I'm puzzled why it's stopped working now.

As an aside, is there anyway to tell the <junit> task to fork into just 
one JVM, rather than one per test class found?  That way the JVM would 
be 'clean' for the unit testing, and would not rely on the classes 
already loaded by the system or ant classloaders, but would not take as 
long as starting a number of JVMs?

Any clues or ideas would be great, but I do want to continue using the 
Ant-based JUnit runner as it has all the nice logging features that 
help with my reporting.

The relevant parts of the build.xml and output are included below...

Andy.

*****

    <!-- test.junit -->
    <target name="test.junit">
        <!-- run junit on all found test classes -->
        <!-- run in a forked JVM in ${build} directory -->
        <junit failureProperty="junit.failed"
               printsummary="on"
               filtertrace="on"
               includeantruntime="false"
               dir="${build}"
               fork="no">
            <sysproperty key="user.dir" value="${basedir}/${build}"/>
            <classpath refid="path.classpath.build"/>
            <!-- save failures (txt format) to the reports directory -->
            <formatter type="plain"/>
            <!-- save failures (xml format) to the reports directory -->
            <formatter type="xml"/>
            <batchtest todir="${reports}">
                <fileset dir="${build}">
                    <include name="**/test/UnitTest*.class"
                             unless="build.junit.pattern"/>
                    <include name="${build.junit.pattern}.class"
                             if="build.junit.pattern"/>
                </fileset>
            </batchtest>
        </junit>
    </target>

*****

BUILD FAILED
java.lang.LinkageError: loader constraints violated when linking org/w3c/dom/Document class
        at org.apache.crimson.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(DocumentBuilderFactoryImpl.java:82)
        at org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.getDocumentBuilder(XMLJUnitResultFormatter.java:93)
        at org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter.startTestSuite(XMLJUnitResultFormatter.java:138)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.fireStartTestSuite(JUnitTestRunner.java:433)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:279)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:797)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:544)
        at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:520)
        at org.apache.tools.ant.Task.perform(Task.java:317)
        at org.apache.tools.ant.Target.execute(Target.java:309)
        at org.apache.tools.ant.Target.performTasks(Target.java:334)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1250)
        at org.apache.tools.ant.Main.runBuild(Main.java:606)
        at org.apache.tools.ant.Main.start(Main.java:195)
        at org.apache.tools.ant.Main.main(Main.java:234)

*****

--
Andrew Beacock
Principal Software Engineer
Nokia
NMP/MSW/SSP/MMS

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message