JUnit Plug with ANT - JUnit

How to run JUnit using ANT?

Let’s see how to run JUnit using ANT. Follow the steps given below.

Step 1: Download Apache Ant

For this download Apache Ant based on the operating system you are working on.
OS Archive Name
Windows apache-ant-1.8.4-bin.zip
Linux apache-ant-1.8.4-bin.tar.gz
Mac apache-ant-1.8.4-bin.tar.gz

Step 2: Set Ant Environment

Now set the ANT_HOME environment variable as per the base directory location, where the ANT libraries are stored on your machine. Let’s assume the Ant libraries are stored in the folder apache-ant-1.8.4.
Sr.No. OS & Description
1

Windows

Set the environment variable ANT_HOME to C:\Program Files\Apache Software Foundation\apache-ant-1.8.4

2

Linux

export ANT_HOME = /usr/local/apache-ant-1.8.4

3

Mac

export ANT_HOME = /Library/apache-ant-1.8.4

Append Ant compiler location to the System Path as follows −

OS Output
Windows Append the string%ANT_HOME\binat the end of the system variable,Path.
Linux export PATH = $PATH:$ANT_HOME/bin/
Mac not required

Step 3: Download JUnit Archive

Now download a JUnit Archive that suits your operating system.
OS Archive Name
Windows junit4.10.jar
Linux junit4.10.jar
Mac junit4.10.jar

Step 4: Create Project Structure

  • Create a folder TestJunitWithAnt in C:\>JUNIT_WORKSPACE.
  • Create a folder src in C:\>JUNIT_WORKSPACE>TestJunitWithAnt.
  • Create a folder test in C:\>JUNIT_WORKSPACE>TestJunitWithAnt.
  • Create a folder lib in C:\>JUNIT_WORKSPACE>TestJunitWithAnt.
  • Create MessageUtil class in C:\>JUNIT_WORKSPACE>TestJunitWithAnt> srcfolder.
Copy junit-4.10.jar onto the folder C:\>JUNIT_WORKSPACE>TestJunitWithAnt>lib.

Create ANT Build.xml

Use <junit> task in Ant to execute our JUnit test cases.
Let’s run the following Ant command.
Now verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JUnit Topics