Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert java task to junit task to run a java class file

 
Micky Morgan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could any one please help me how to run jar file using junit task. To be more precise, how could I convert (the below java ant task runs OK) to JUnit ant task.

I am currently using Ant 1.6.5 and JUnit 4.1. The reason, I want to run this as Junit because, I want to create HTML reports which is possible only if I use JUnit Task...

Note that com.acme.MyTester.class is inside of MyTester.jar file. My Classpath included this jar file...

<target name="run" description="Run the jar file">
<java classname="org.junit.runner.JUnitCore" fork="yes" >

<arg value="com.acme.MyTester"/>

<sysproperty key="loginname" value="admin" />
<sysproperty key="password" value="admin" />

<classpath refid="ccp" />
</java>

</target>
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you not just run the standard <junit /> task against your TestCase before you wrap it up into a Jar?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just use the line

<classpath refid="ccp" />

in your junit task, too?
 
Micky Morgan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks fpr your responses...Could you please elaborate with detailed responses....I am finding hard time to get it work using junit ant task...an example would be of very helpful...

Thanks in advance...
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your junit task invocation look like? Did you include the classpath line like Ilja suggested?
 
Micky Morgan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my junit task...

<target name="run" description="Run the jar file">
<junit fork="yes" printsummary="yes" haltonfailure="yes" >

<arg value="com.acme.MyTester"/>
<sysproperty key="loginname" value="admin" />
<sysproperty key="password" value="admin" />

<formatter type="xml" />
<classpath refid="ccp" />
</junit>

</target>
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The docs of the junit task do not not mention an "arg" element, and you do seem to be missing either a test or a batchtest element. Have you tried replacing "<arg value="com.acme.MyTester"/>" by "<test name="com.acme.MyTester"/>" (assuming that MyTester is a TestCase) ?
[ November 27, 2006: Message edited by: Ulf Dittmer ]
 
Micky Morgan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Ulf Dittmer and others for your help. After changing <arg> tag with <test> tag, it started working...

Thanks again...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic