aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Not able run junit test cases from ANT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Not able run junit test cases from ANT" Watch "Not able run junit test cases from ANT" New topic
Author

Not able run junit test cases from ANT

Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141
hi,
This is the first time i m writing a ant scrip and I am not able to run junit test from ant file.
Below is the build.xml



And the error :

SampleClassTest

java.lang.ClassNotFoundException: SampleClassTest at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source)

i know its not able to find the class itself but don't know why?
Please tell me where to make changes it to work.


Thanks


rawat
SCJP 1.4
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Can you give us a little more info? what ant target were you calling exactly?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141
Hi,

I called "tests" ( which i think calls run-tests ).

Rest all ant targets are working fine. Compiling, creating of jars, directories are working. But when it reaches run-tests, it gives error.

If i make haltonfailure="no" in run-tests target, then HTML files are also generated but all with the same error.

Hope this info is ok.


Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

I think it might be that your classapth says:



But your batchtests refers to



Should the batchtests not match ${build.testcases}/${unittest}?

Also run your anyt with debug on, you'll quickly see what classpath the batchtests is running with.

Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141
Hi Martin,

What i can make out from classpath tag that its putting all the compiled junit test class files location and source code jar into the class path. Am i right on this?


# <classpath>
# <pathelement location="${build.testcases}/${unittest}" /> --> putting compiled junit test class files
# <pathelement location="${build.lib}/${app.name}.jar" /> --> putting source code jar
# <pathelement path="${java.class.path}" />
# </classpath>

To run test files, these are the things required. right?
Then why <fileset dir="${build.testcases}/${unittest}"> ?

In fact i did changed fileset to ${build.testcases}/${unittest} but still the error is same.


Moreover, i can see source code jar file in the class path but not junit test class files?

Please tell me how to run in debug mode so that i can check in that too.








Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

you can run debug mode with ant -v or ant -d IIRC (sorry this is being replied to on my iPhone)
Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141
This is the output in debug mode

run-tests:
[junit] Implicitly adding C:\eclipse\plugins\org.junit4_4.3.1\junit.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant-launcher.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant-junit.jar to CLASSPATH
[junit] Executing 'C:\Program Files\Java\jre1.5.0\bin\java.exe' with arguments:
[junit] '-classpath'
[junit] 'C:\Documents and Settings\localadmin\rawat-workspace\JunitSamples\build\lib\junitsamples.jar;C:\Program Files\Java\jdk1.5.0;C:\Program Files\Java\jdk1.5.0\lib;C:\eclipse\plugins\org.junit4_4.3.1\junit.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant-launcher.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant-junit.jar'
[junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
[junit] 'AllTests'
[junit] 'filtertrace=true'
[junit] 'haltOnError=false'
[junit] 'haltOnFailure=false'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
[junit] 'showoutput=true'
[junit] 'outputtoformatters=true'
[junit] 'logtestlistenerevents=true'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,C:\Documents and Settings\localadmin\rawat-workspace\JunitSamples\reports\raw\TEST-AllTests.xml'
[junit] 'crashfile=C:\Documents and Settings\localadmin\rawat-workspace\JunitSamples\junitvmwatcher1389234997.properties'
[junit] 'propsfile=C:\Documents and Settings\localadmin\rawat-workspace\JunitSamples\junit1726199245.properties'
[junit]
[junit] The ' characters around the executable and arguments are
[junit] not part of the command.
[junit] Running AllTests
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Test AllTests FAILED
[junit] Implicitly adding C:\eclipse\plugins\org.junit4_4.3.1\junit.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant-launcher.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant-junit.jar to CLASSPATH
[junit] Executing 'C:\Program Files\Java\jre1.5.0\bin\java.exe' with arguments:
[junit] '-classpath'
[junit] 'C:\Documents and Settings\localadmin\rawat-workspace\JunitSamples\build\lib\junitsamples.jar;C:\Program Files\Java\jdk1.5.0;C:\Program Files\Java\jdk1.5.0\lib;C:\eclipse\plugins\org.junit4_4.3.1\junit.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant-launcher.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant.jar;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant-junit.jar'
[junit] 'org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner'
[junit] 'SampleClassTest'
[junit] 'filtertrace=true'
[junit] 'haltOnError=false'
[junit] 'haltOnFailure=false'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.SummaryJUnitResultFormatter'
[junit] 'showoutput=true'
[junit] 'outputtoformatters=true'
[junit] 'logtestlistenerevents=true'
[junit] 'formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,C:\Documents and Settings\localadmin\rawat-workspace\JunitSamples\reports\raw\TEST-SampleClassTest.xml'
[junit] 'crashfile=C:\Documents and Settings\localadmin\rawat-workspace\JunitSamples\junitvmwatcher1992137603.properties'
[junit] 'propsfile=C:\Documents and Settings\localadmin\rawat-workspace\JunitSamples\junit477953495.properties'
[junit]



I can se 'C:\Documents and Settings\localadmin\rawat-workspace\JunitSamples\build\lib\junitsamples.jar is getting reflected into class path but not the directory. But why?

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

OK, your test classes are being compile to ${build.testcases}, so you need to have that in the classpath for when you run JUnit.
Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141
Hi Martin,

Sorry for the delay reply, Its finally working and generating all the unit test reports with all proper information.

Thanks

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

No problem, glad you fixed it!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able run junit test cases from ANT