2009-11-06 25 views
4

我還沒有完成與file.encoding and ant。如何設置file.encoding在ant中進行junit測試? junit ant任務不支持編碼屬性像javac任務確實。如何在ant中爲junit測試設置file.encoding?

我試過運行«ant -Dfile.encoding = UTF-8»和«ANT_OPTS =「 - Dfile.encoding = UTF-8」ant»沒有成功。測試中的System.getProperty(「file.encoding」)仍然返回MacRoman

回答

16

JUnit支持子元素<jvmarg ...>,它應該做你想做的。

<junit fork="yes"> 
    <jvmarg value="-Dfile.encoding=UTF-8"/> 
    ... 
</junit> 

我假設你正在使用的fork=yes屬性,因爲這會啓動試運行一個新的JVM,所以你送入螞蟻在命令行ant -Dfoo=bar不一定傳播到JVM運行測試的參數。

相關問題