Summary: | Classpath use seems to be broken in junit ant task? | ||
---|---|---|---|
Product: | Ant | Reporter: | andrew cooke <andrew> |
Component: | Optional Tasks | Assignee: | Ant Notifications List <notifications> |
Status: | REOPENED --- | ||
Severity: | regression | CC: | andrew, ashish.soni, francis.andre.kampbell, jglick, nico.kruber |
Priority: | P2 | ||
Version: | 1.9.7 | ||
Target Milestone: | 1.9.7 | ||
Hardware: | All | ||
OS: | All | ||
Attachments: |
junit.jar: content
junit.jar |
Description
andrew cooke
2013-04-12 22:36:20 UTC
Correction: "(the above project uses ant; alternatively" should be "(the above project uses IVY; alternatively..." I'm not sure this is a good bug report, sorry - the details are mainly at the SO question. If you'd prefer me to repeat them here I can do so. Basically - I provide a classpath to the junit task, but it still gives a class not found error. I am now working on this repo. The example referred to above is tagged as "classpath problem" so to check out please do: hg clone ssh://hg@bitbucket.org/isti/java-example cd java-example hg update -r "classpath problem" Thanks, Andrew Things are clearer now. The following: hg clone ssh://hg@bitbucket.org/isti/java-example cd java-example hg update -r "works with 1.8.4" ant bootstrap test works (gives an error because my test is missing a constructor) with Ant 1.8.4 but fails with Ant 1.9.0. This is with a "virgin" Ant install. The "bootstrap" copies the Ivy jar into ~/.ant/lib and then "test" downloads Junit jar to the local lib directory. With Ant 1.8.4, having the Junit jar in the classpath for the junit task works just fine. As documented at http://ant.apache.org/manual/Tasks/junit.html (item 5). But with Ant 1.9.0 this code DOES NOT WORK. Michael? It looks like the class search is being delegated to the System's classloader rather than being handled by the Ant Classloader (the system Classloader has no knoweldge of JUnit since JUnit isn't on the core Ant Classpath, but is added to the JUnit task by Ivy). Given some JUnit classes must have already been loaded to have reached this point, the Ant Classloader can see the JUnit jars loaded by Ivy, but the Split Classloader seems to be delegating incorrectly when trying to load classes used by the JUnit Runner. I suspect the list of 'split classes' in JUnitTask needs expanded to include the classes added for the @Ignore changes introduced in Ant 1.9.0. I'll do a bit more investigation on this issue to see if there are any other issues caused by JUnit being inherited from an external source rather than being in the ANTLIB directory whilst I fix this issue. In the meantime, copying your JUnit JAR into your ANTLIB directory will allow Ant to pickup the dependent classes required to launch the JUnit task if you want to continue using Ant 1.9.0. Thanks. I've switched back to 1.8 for now (I know that I can fix it by moving jars, but the motivation is to have the build bootstrap itself completely to simplify the process for other users). Fixed under SVN revision 1470668. Looks like this bug only affected calls to <junit> with fork="false" (the unfortunate default), which should be considered deprecated as far as I am concerned; with fork="true" it is reported to work in 1.9.0. I'm still seeing this problem as of ant 1.9.1 I have a unit test flagged as such: @RunWith(SpringJUnit4ClassRunner.class) and an ant test target that contains <junit printsummary="yes" haltonfailure="yes" fork="true" forkmode="once" tempdir="${report.tests.dir}"> <classpath refid="test.classpath.run"/> <formatter type="plain"/> <batchtest fork="yes" todir="${report.tests.dir}"> <fileset dir="${src.tests.dir}"> <include name="**/*IntegrationTestCase*.java"/> </fileset> </batchtest> </junit> my classpath is built via ivy. The ant test run does not honor the 'RunsWith' annotation. A stack trace demonstrates this. Running in eclipse works fine. Actually, I haven't the vaguest idea. I've tried using ant 1.8.4 with and without the junit4 jar in the lib directory, as well as ant 1.9.1. I'm flumoxed. This may very well be my stupidity someplace. Totally my bad.. I didn't see that this particular case I was fiddling with extended junit3 TestCase. Time to go shave heads.. mine and someone else's. It looks like this fix actually broke JUnit4 for me. Everything up to (and including) 1.9.0 works fine, 1.9.1-1.9.3 do not. I created a fairly minimal test case at my git repository https://github.com/NicoK/ant-1.9-junit git clone https://github.com/NicoK/ant-1.9-junit.git cd ant-1.9-junit.git ant test (I tested 1.9.0 by adding it to the test-lib directory and setting includeantruntime="false" for the JUnit task in the ant build file) actually, only providing ant-junit-1.9.0.jar in the test-lib folder is sufficient to make it work again Re-closing issue since it can't be replicated with the test case in #13 on a clean build of Ant 1.9.6. As per ant version C:\Users\fandre\Documents\git\javacc>ant -version Apache Ant(TM) version 1.9.7 compiled on April 9 2016 this issue is always present with the script below <junit printsummary="yes" haltonfailure="no"> <classpath> <pathelement location="classes" /> <pathelement location="junit" /> <pathelement location="lib/junit.jar" /> </classpath> <batchtest fork="no" todir="."> <fileset dir="junit"> <include name="**/*Test.*" /> </fileset> <formatter type="failure"/> <!-- I want to see something ... --> <formatter type="plain" usefile="false"/> </batchtest> </junit> unittest: [delete] Deleting directory C:\Users\fandre\Documents\git\javacc\test.tmp [mkdir] Created dir: C:\Users\fandre\Documents\git\javacc\test.tmp [delete] Deleting directory C:\Users\fandre\Documents\git\javacc\junit [mkdir] Created dir: C:\Users\fandre\Documents\git\javacc\junit [javac] Compiling 6 source files to C:\Users\fandre\Documents\git\javacc\junit BUILD FAILED C:\Users\fandre\Documents\git\javacc\build.xml:229: Using loader AntClassLoader[C:\Apache Software Foundation\apache-ant-1.9.7\lib\ant-launcher.jar;C:\Apache Software Foundation\apache-ant-1.9.7\lib\ant.jar;C:\Apache Software Foundation\apache-ant-1.9.7\lib\ant-junit.jar;C:\Apache Software Foundation\apache-ant-1.9.7\lib\ant-junit4.jar;C:\Users\fandre\Documents\git\javacc\classes;C:\Users\fandre\Documents\git\javacc\junit;C:\Users\fandre\Documents\git\javacc\lib\junit.jar] on class org.apache.tools.ant.taskdefs.optional.junit.FailureRecorder: java.lang.NoClassDefFoundError: junit/framework/TestListener at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java:1407) at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1085) at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader.java:58) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.apache.tools.ant.taskdefs.optional.junit.FormatterElement.createFormatter(FormatterElement.java:287) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1617) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:1021) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:2105) at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:832) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293) at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:435) at org.apache.tools.ant.Target.performTasks(Target.java:456) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405) at org.apache.tools.ant.Project.executeTarget(Project.java:1376) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1260) at org.apache.tools.ant.Main.runBuild(Main.java:854) at org.apache.tools.ant.Main.startAnt(Main.java:236) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112) Caused by: java.lang.ClassNotFoundException: junit.framework.TestListener at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 49 more Created attachment 34497 [details]
junit.jar: content
Created attachment 34498 [details]
junit.jar
Wjunit classpath resolution for junit.jar is working with ant 1.9.3. Did not test with 1.9.4 or 1.9.5 or 1.9.6. Wjunit classpath resolution for junit.jar is working with ant 1.9.3. Did not test with 1.9.4 or 1.9.5 or 1.9.6. |