user130076
user130076

Reputation:

Buildr - put test resources on classpath

I'm trying to use buildr to build a Java project of mine. I have a bunch of concordion tests and HTML specifications, located like so:

src/test/java/spec/x/y/z/SomethingTest.java
src/test/resources/spec/x/y/z/Something.html

buildr finds the actual test code (SomethingTest.java) and runs it, but the HTML does not end up on the classpath and so the test fails. I get the following error:

[junit] Testcase: [Concordion Specification for 'Something'] took 0.002 sec
[junit]     Caused an ERROR
[junit] Resource '[classpath: /x/y/z/Something.html]' not found
[junit] java.io.IOException: Resource '[classpath: /x/y/z/Something.html]' not found
[junit]     at org.concordion.internal.ClassPathSource.createInputStream(ClassPathSource.java:15)
[junit]     at org.concordion.internal.XMLSpecificationReader.readSpecification(XMLSpecificationReader.java:25)
[junit]     at org.concordion.Concordion.process(Concordion.java:30)
[junit]     at org.concordion.Concordion.process(Concordion.java:26)
[junit]     at org.concordion.internal.FixtureRunner.run(FixtureRunner.java:18)
[junit]     at org.concordion.integration.junit4.ConcordionRunner$1.evaluate(ConcordionRunner.java:113)
[junit]     at org.concordion.integration.junit4.ConcordionRunner.runChild(ConcordionRunner.java:104)
[junit]     at org.concordion.integration.junit4.ConcordionRunner.runChild(ConcordionRunner.java:18)
[junit] 
[junit] TEST x.y.z.SomethingTest FAILED

My buildfile is as follows:

repositories.remote = 'http://www.ibiblio.org/maven2'

JODA = 'joda-time:joda-time:jar:2.0'
CONCORDION = 'org.concordion:concordion:jar:1.4.2'
XERCES = 'xerces:xercesImpl:jar:2.8.1'
XOM = 'xom:xom:jar:1.2.5'

define 'my-project' do
  project.version = '0.0.1'
  compile.with JODA
  test.with XERCES, XOM, CONCORDION
  package :jar
end

I have tried to force the HTML files onto the classpath using variations on Java.classpath << 'src/test/resources/x/y/z' and test.resources.include but to no avail. I'm sure I'm just missing something simple. Any help would be greatly appreciated.

Upvotes: 0

Views: 1498

Answers (3)

Soulman
Soulman

Reputation: 3030

Buildr should in theory copy resources to <project-dir>/target/test/resources and include this in the classpath when running tests. Check to see if this directory exists, and if so, if it is empty.

Are you running Eclipse while this problem occurs? If so, this could be a conflict between buildr and eclipse. Try to shut down Eclipse, then run buildr clean and buildr test.

I've seen similar issues, and my theory is that Eclipse creates empty target directories as soon as they are deleted, for instance by Buildr. Then Buildr checks the timestamp of the target directory and sees that it is more recent than any of the source resources, and figures that it must be up-to-date. Thus, any program that creates empty target resource directories could in theory cause this problem.

Upvotes: 0

Peter Donald
Peter Donald

Reputation: 461

By default Buildr uses mavens convention of separating source code and resources. So test resources need to be put in the "src/test/resources" directory.

Upvotes: 3

bodtx
bodtx

Reputation: 609

be sure you're using this.getClass().getClassLoader().getResourceAsStream([your URL]);

and not just new File([your URL]);

see http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/ClassLoader.html#getResourceAsStream%28java.lang.String%29

Upvotes: 0

Related Questions