Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able run junit test cases from ANT

 
Himanshu Rawat
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give us a little more info? what ant target were you calling exactly?
 
Himanshu Rawat
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem, glad you fixed it!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic