Installing JUnit
Problem
You need
to
configure JUnit so you can run your tests using Ant. Although you
have added junit.jar to your classpath, you
still see errors.
Solution
You have three possible solutions:
Install Ant’s
optional.jaras well as JUnit’sjunit.jarin theANT_HOME/libdirectory.Ensure that neither
optional.jarnorjunit.jaris in theANT_HOME/libdirectory. Then set up a classpath in your buildfile that includes both JAR files.Ensure that neither
optional.jarnorjunit.jaris in theANT_HOME/libdirectory. Then set yourCLASSPATHenvironment variable to include both JAR files.
Discussion
Ant’s
junit
task is implemented by a class named
JUnitTask, which is found in the
optional.jar file that ships with the Ant
distribution. Ant includes many so-called
“optional” tasks, which generally
depend on external libraries in order to function. In the case of the
junit task, junit.jar is
required. It is your responsibility to download JUnit and properly
configure it to work with Ant.
Class loading problems are common in cases where optional Ant tasks
depend on external libraries such as junit.jar.
The Java ClassLoader instance that loads the
JUnitTask class must also be able to load various
JUnit classes. For the proper classes to be visible, you must follow
one of the three solutions that were just mentioned.
You generally install Ant’s
optional.jar in the
ANT_HOME
/lib directory, so
the easiest way to configure JUnit is to also install
junit.jar in
ANT_HOME
/lib. Example 3-6 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access