2012-10-09 58 views
2

我正在使用Maven 3.0.3,JUnit 4.8.1和Java 1.6。我有一個JUnit測試文件...無法在Maven多模塊項目的JUnit測試中找到資源

@Before 
public void loadTestProps() throws IOException, GeneralSecurityException { 
    final InputStream in = getClass().getClassLoader().getResourceAsStream("test.properties"); 
    testProps = new Properties(); 
    testProps.load(in); 

「test.properties」沒有得到拾取(輸入流對象爲空)。我的項目結構如下:

父 + --- pom.xml的
+ ---戰爭模塊
+ ------ pom.xml的
+ ------ SRC /測試/ JAVA/JUnit的文件
+ ------的src /測試/資源/ test.properties
+ ---耳模塊
+ -------的pom.xml

我寧願將我的「src/test/resources」目錄保存在我的WAR模塊中,因爲測試只與WAR文件有關。有沒有一種方法可以重寫上述Java以查找我的「test.properties」,還是必須將該文件移出WAR模塊?

+0

是否將src/test/resources定義爲源文件夾? –

+0

這應該工作得很好。測試在IDE和命令行中都失敗了嗎?你確定在任何地方都沒有拼寫錯誤嗎? –

+0

我們可以看到戰爭模塊的pom.xml嗎? – Kkkev

回答

0

而不是 getResourceAsStream(「test.properties」);您應該使用 getResourceAsStream(「/ test.properties」);

相關問題