Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Ant & JUnit java.lang.NullPointerException

Reply
Thread Tools

Ant & JUnit java.lang.NullPointerException

 
 
lionelv@gmail.com
Guest
Posts: n/a
 
      11-11-2007
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
[antlibrg.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\UpdateMan ager.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\TCIF igures.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\TCIS wingWorker.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\TCIW orksConstants.class
is up to date.

BUILD FAILED
c:\TCIWorks\TCIWorksApplication\build.xml:134:
java.lang.NullPointerException
at
org.apache.tools.ant.dispatch.DispatchUtils.execut e(DispatchUtils.java:
115)
at org.apache.tools.ant.Task.perform(Task.java:34
at org.apache.tools.ant.Target.execute(Target.java:35 7)
at org.apache.tools.ant.Target.performTasks(Target.ja va:385)
at org.apache.tools.ant.Project.executeSortedTargets( Project.java:
1329)
at org.apache.tools.ant.Project.executeTarget(Project .java:129
at
org.apache.tools.ant.helper.DefaultExecutor.execut eTargets(DefaultExecutor.java:
41)
at org.apache.tools.ant.Project.executeTargets(Projec t.java:1181)
at org.apache.tools.ant.Main.runBuild(Main.java:69
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.JUnit Task.execute(JUnitTask.java:
753)
at org.apache.tools.ant.UnknownElement.execute(Unknow nElement.java:
28
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknow n Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
org.apache.tools.ant.dispatch.DispatchUtils.execut e(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.JUnit Task.execute(JUnitTask.java:
753)
at org.apache.tools.ant.UnknownElement.execute(Unknow nElement.java:
28

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      11-12-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ant/JUnit question Tim Java 3 12-10-2003 12:22 AM
using ANT for regular nightly invocation of JUnit simonspoerri Java 4 11-20-2003 08:14 PM
Re: Junit Ant Task Christopher Blunck Java 1 08-19-2003 04:48 PM
junit ant task problems loading up a .properties file Scout Java 0 08-04-2003 05:30 PM
Junit Test From Ant--java.lang.LinkageError Tom Koenning Java 0 07-28-2003 07:11 PM



Advertisments