2012-03-10 57 views
0

我試圖使用buildr來構建我的Java項目。我有一大堆的concordion測試和HTML規格,位於象這樣:Buildr - 將類測試資源放在類路徑上

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

buildr發現實際的測試代碼(SomethingTest.java)並運行它,但HTML不會在classpath中結束,因此測試失敗。我得到以下錯誤:

[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 

buildfile如下:

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 

我曾嘗試到HTML文件強制使用上對Java.classpath << 'src/test/resources/x/y/z'test.resources.include,但無濟於事變化的類路徑。我相信我只是想念一些簡單的東西。任何幫助將不勝感激。

+0

如何訪問資源?將.java文件旁邊的html文件解決問題? – 2012-03-11 17:21:15

回答

2

默認情況下Buildr使用分離的源代碼和資源的內行約定。所以測試資源需要放在「src/test/resources」目錄下。

+0

很確定這是正確的答案。資源文件夾未拾取。您可以隨時更改您的項目的佈局以適應。 – 2012-11-13 18:52:08

+0

以某種方式幫助我完成了一個完全gradle項目和類型安全配置。謝謝! – craastad 2014-09-04 12:46:46

0

Buildr理論上應該將資源拷貝到<project-dir>/target/test/resources,並在運行測試時將其包含在類路徑中。檢查該目錄是否存在,如果存在,是否爲空。

在發生此問題時是否運行Eclipse?如果是這樣,這可能是buildr和eclipse之間的衝突。嘗試關閉Eclipse,然後運行buildr cleanbuildr test

我見過類似的問題,我的理論是Eclipse一旦刪除了它們就會創建空的目標目錄,例如Buildr。然後,Buildr檢查目標目錄的時間戳,並發現它比任何源資源都更新,並指出它必須是最新的。因此,任何創建空目標資源目錄的程序在理論上都會導致這個問題。