【发布时间】:2011-07-07 14:35:08
【问题描述】:
我有一个测试用例(它实际上是一个集成测试),它使用包含斯堪的纳维亚字母的用户名登录。问题是当我从命令行运行 Ant 任务时,身份验证失败,因为编码不正确(应该是 UTF-8)。当我从 Eclipse 运行它时,测试运行得很好,但不是从命令行运行。到目前为止,我已经尝试在 Ant 目标中告诉 Ant 正确的编码:
<target name="run_tests">
<junit fork="no" haltonfailure="no">
<jvmarg value="-Dfile.encoding=UTF-8"/>
<formatter type="xml" usefile="true" />
<classpath refid="test.classpath" />
<test name="com.company.integration.AllIntegrationTests" />
</junit>
</target>
从命令行:
ant -D"file.encoding=UTF-8" run_tests
这些都不起作用。不管我做什么,测试仍然失败,测试报告说:
<property name="file.encoding" value="cp1252" />
就像我说的,如果我从 Eclipse 中运行它,一切都运行良好。我还注意到,如果我通过将编码更改为 ISO-8859-1 来修改 Eclipse 中的运行配置以进行测试,则测试会像预期的那样失败。那么显然可以改变编码,但是你是怎么做到的呢?
【问题讨论】: