The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by ole_ersoy]

Hello,

The ant book is phenomenally helpful! It Rocks!

I'm currently trying to use the "External Resources" code in chapter 4. I
added my test file to the classpath and implemented the getFile(String
fileName)
in my test case.

When I run the build I get a null pointer exception.

I tried running the chapter 4 build that came with the book, and I get the
following:


Buildfile: /home/ole/workspace/antbook/Sections/Learning/ch04/build.xml

init:
[mkdir] Created dir:
/home/ole/workspace/antbook/Sections/Learning/ch04/build/classes
[mkdir] Created dir:
/home/ole/workspace/antbook/Sections/Learning/ch04/dist
[echo] Building AntBook - Testing Examples

compile:
[javac] Compiling 1 source file to
/home/ole/workspace/antbook/Sections/Learning/ch04/build/classes

test-init:
[mkdir] Created dir:
/home/ole/workspace/antbook/Sections/Learning/ch04/build/test
[copy] Copying 1 file to
/home/ole/workspace/antbook/Sections/Learning/ch04/build/test
[copy] Copied 1 empty directory to
/home/ole/workspace/antbook/Sections/Learning/ch04/build/test
[mkdir] Created dir:
/home/ole/workspace/antbook/Sections/Learning/ch04/build/test/data
[mkdir] Created dir:
/home/ole/workspace/antbook/Sections/Learning/ch04/build/test/reports

test-compile:
[javac] Compiling 4 source files to
/home/ole/workspace/antbook/Sections/Learning/ch04/build/test

test-batch:
[junit] Testsuite: org.example.antbook.ant.lucene.HtmlDocumentTest
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.073 sec
[junit] null
[junit] Testcase:
testDoc(org.example.antbook.ant.lucene.HtmlDocumentTest): FAILED
[junit] Title expected:<Test Title> but was:<null>
[junit] junit.framework.ComparisonFailure: Title expected:<Test>
Title> but was:<null>
[junit] at
org.example.antbook.ant.lucene.HtmlDocumentTest.testDoc(HtmlDocumentTest.java:20)

[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
[junit] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

[junit] at
org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:57smilie

[junit] at
org.eclipse.ant.internal.core.ant.InternalAntRunner.run(InternalAntRunner.java:376)

[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
[junit] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

[junit] at
org.eclipse.ant.core.AntRunner.run(AntRunner.java:341)
[junit] at
org.eclipse.ant.ui.internal.launchConfigurations.AntLaunchDelegate$1.run(AntLaunchDelegate.java:203)

[junit] at java.lang.Thread.run(Thread.java:536)
[junit] null
[junit] null

Total time: 6 seconds

When I run with my build.xml the code just gets me a nullpointer exception,
and the test case does not even evaluate.

I would greatly appreciate it if you could help me understand what I need to
do to make this run. My goal is to be able to indicate where test files are
located via build.xml.

Best Regards,
- Ole
import-bot (20211) [Avatar] Offline
#2
Re: Ch. 4 Test Fails
[Originally posted by erikhatcher]

Ole - thanks for the kind words!

As for the code from the book - that test case was designed to fail as a
demonstration of what
happens with Ant and reporting.

I'm not sure why its failing in your case. When you say you've put it in the
classpath, what does
that mean?

Look at using <sysproperty> within <junit> to pass paths to test cases for
control allowing Ant
and IDE's to run the same test cases. I hope this helps.
import-bot (20211) [Avatar] Offline
#3
Re: Ch. 4 Test Fails
[Originally posted by ole_ersoy]

Erik,

That's brilliant. Thanks!