Ant & JUnit java.lang.NullPointerException

L

lionelv

I'm migrating from Netbeans to setup all of my compiling, packaging
and testing. However, I'm having troubles getting the testing part
working. Here's the snippet of code I'm currently using:

<property name="src" value="src"/>
<property name="lib" value="lib"/>
<property name="build" value="build"/>
<property name="dist" value="dist"/>
<property name="dist-lib" value="${dist}/lib"/>
<property name="src.lib.runtime" value="${lib}/runtime"/>
<property name="classes" value="${build}/classes/"/>
<property name="jar.executable" value="${dist}/$
{ant.project.name}.jar"/>
<property name="test.src" value="test"/>
<property name="test.execute" value="${build}/test"/>
<property name="test.reports" value="${test.execute}/reports"/>

<!-- Runs the JUnit Tests -->
<target name="test">
<mkdir dir="${test.reports}"/>
<copy todir="${test.execute}">
<fileset dir="${src}"/>
</copy>
<copy todir="${test.execute}">
<fileset dir="${test.src}"/>
</copy>
<javac srcdir="${test.execute}"
classpath="${classpath}"
debug="true"
source="1.5"
/>
<junit dir="${test.execute}">
<test name="tciworks.analysis.BayesianTest"/>
</junit>
<!--junit printsummary="yes">
<formatter type="plain"/>
<batchtest fork="yes" todir="${test.reports}">
<fileset dir="${test.execute}}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit-->
</target>

Code being tested is in ${src}
Test cases are in ${test.src}.
All of the source is copied to ${test.execute} and compiled there.

When I try to test I get the following (trimmed) error:

Apache Ant version 1.7.0 compiled on December 13 2006
Buildfile: build.xml
Detected Java version: 1.5 in: c:\Program Files\Java\jdk1.5.0_06\jre
Detected OS: Windows XP
[antlib:eek:rg.apache.tools.ant] Could not load definitions from resource
org/apache/tools/ant/antlib.xml. It could not be found.
[snip]
test:
[mkdir] Skipping c:\TCIWorks\TCIWorksApplication\build\test
\reports because it already exists.
[copy] tciworks\TCIWorks.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\TCIWorks.java is up to date.
[copy] tciworks\UpdateManager.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\UpdateManager.java is up to
date.
[copy] tciworks\analysis\AbstractObjective.java omitted as c:
\TCIWorks\TCIWorksApplication\build\test\tciworks\analysis
\AbstractObjective.java is up to date.
[snip]
[javac] tciworks\util\TCIFigures.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\util\TCIFigures.class is up
to date.
[javac] tciworks\util\TCISwingWorker.class skipped - don't know
how to handle it
[javac] tciworks\util\TCISwingWorker.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\util\TCISwingWorker.class is
up to date.
[javac] tciworks\util\TCIWorksConstants.class skipped - don't know
how to handle it
[javac] tciworks\util\TCIWorksConstants.java omitted as c:\TCIWorks
\TCIWorksApplication\build\test\tciworks\util\TCIWorksConstants.class
is up to date.

BUILD FAILED
c:\TCIWorks\TCIWorksApplication\build.xml:134:
java.lang.NullPointerException
at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:
115)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:
1329)
at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:
41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:698)
at org.apache.tools.ant.Main.startAnt(Main.java:199)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
Caused by: java.lang.NullPointerException
at org.apache.tools.ant.types.Path.add(Path.java:261)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:
753)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:
288)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:
105)
... 11 more
--- Nested Exception ---
java.lang.NullPointerException
at org.apache.tools.ant.types.Path.add(Path.java:261)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:
753)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:
288)
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

I'm migrating from Netbeans to setup all of my compiling, packaging
and testing. However, I'm having troubles getting the testing part
working. Here's the snippet of code I'm currently using:
<junit dir="${test.execute}">
<test name="tciworks.analysis.BayesianTest"/>
</junit>
<!--junit printsummary="yes">
<formatter type="plain"/>
<batchtest fork="yes" todir="${test.reports}">
<fileset dir="${test.execute}}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
</junit-->
</target>

Code being tested is in ${src}
Test cases are in ${test.src}.
All of the source is copied to ${test.execute} and compiled there.

When I try to test I get the following (trimmed) error:

Apache Ant version 1.7.0 compiled on December 13 2006
Buildfile: build.xml
Detected Java version: 1.5 in: c:\Program Files\Java\jdk1.5.0_06\jre
Detected OS: Windows XP
Caused by: java.lang.NullPointerException
at org.apache.tools.ant.types.Path.add(Path.java:261)

Very hard to say without having the code to play with.

You could try replace:

<junit dir="${test.execute}">

with:

<junit fork="on" dir="${test.execute}">

because I have often had problems without that.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top