Pradeep's Blog

Google

Monday, March 20, 2006

How to integrate Junit into Ant?

Ant provides a flexible JUnit task for compling and executing JUnit tests. I hope that you all know what how test classes are written in java. Consider that we have a class named metricEngine and a class named metricEngineTest to test it.
The first thing that has to be done is that both the classes needs to be compiled. This can be done in Ant as follows (considering that both the files are in basedir itself).


<target description="Compiling Files." depends="init" name="compile.source">
<echo>Compiling Files
<javac destdir="${destdir}" srcdir="${basedir}" target="1.5" source="1.5">
<classpath refid="classpath">
<include name="**">
</javac>
</target>


The classpath includes the list of libary files needed to compile these files. They can be set as follows (consider that the basedir/lib contains all the required library (jar) files.


<path id="classpath">
<fileset dir="${basedir}/lib">
<include name="*.jar">
</fileset>
</path>


Now that both the files have been compiled we can test them, this can be done as follows


<target description="Runs the test suite" depends="compile.test" name="test">
<printsummary="yes" fork="yes" haltonfailure="no" showoutput="yes">
<formatter type="plain" usefile="false">
<classpath refid="classpath">
<lt todir="${basedir}/test-result.txt" fork="yes">
<fileset dir="${destdir}">
<include name="**/metricEngineTest.class">
</fileset>
</batchtest>
</junit>
</target>


MOre information on the JUnit tag can be found with ANT Documentation.

1 Comments:

  • Hi,

    I mostly visits this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]You have really contiributed very good info here pradeepselvaraj.blogspot.com. Do you pay attention towards your health?. In plain english I must warn you that, you are not serious about your health. Recent Research shows that about 50% of all U.S. adults are either obese or weighty[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] So if you're one of these citizens, you're not alone. In fact, most of us need to lose a few pounds once in a while to get sexy and perfect six pack abs. Now next question is how you can achive quick weight loss? [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss[/url] is really not as tough as you think. You need to improve some of you daily habbits to achive weight loss in short span of time.

    About me: I am webmaster of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also health expert who can help you lose weight quickly. If you do not want to go under difficult training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for effective weight loss.

    By Anonymous Anonymous, at 8:01 PM  

Post a Comment

<< Home