aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to convert java task to junit task to run a java class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to convert java task to junit task to run a java class file" Watch "How to convert java task to junit task to run a java class file" New topic
Author

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

Micky Morgan
Greenhorn

Joined: Sep 20, 2006
Posts: 19
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

Joined: Apr 14, 2004
Posts: 10336

Could you not just run the standard <junit /> task against your TestCase before you wrap it up into a Jar?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Why don't you just use the line

<classpath refid="ccp" />

in your junit task, too?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Micky Morgan
Greenhorn

Joined: Sep 20, 2006
Posts: 19
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
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
What does your junit task invocation look like? Did you include the classpath line like Ilja suggested?


Ping & DNS - my free Android networking tools app
Micky Morgan
Greenhorn

Joined: Sep 20, 2006
Posts: 19
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
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
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

Joined: Sep 20, 2006
Posts: 19
Thanks to Ulf Dittmer and others for your help. After changing <arg> tag with <test> tag, it started working...

Thanks again...
 
jQuery in Action, 2nd edition
 
subject: How to convert java task to junit task to run a java class file