开发者

Setting encoding for jUnit task in Ant

开发者 https://www.devze.com 2023-03-17 19:35 出处:网络
I have a test case (it is really an integration test) which logs in with a username containing Scandinavian letters. The problem is that when I run the Ant task from command line, the authentication f

I have a test case (it is really an integration test) which logs in with a username containing Scandinavian letters. The problem is that when I run the Ant task from command line, the authentication fails because the encoding is not correct (it should be UTF-8). The test runs just fine when I run it from Eclipse, but not from command line. So far I've tried to tell the correct encoding to Ant both in the Ant target:

<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>

and from the command line:

ant -D"file.encoding=UTF-8" run_tests

Neither of these work. Whatever I do, the tests still fail and the test report says:

开发者_开发技巧<property name="file.encoding" value="cp1252" />

Like I said, if I run it from Eclipse, everything works beautifully. I also noticed that if I modify the run configuration in Eclipse for the test by changing the encoding to ISO-8859-1, the test fails like expected. So obviously it is possible to change the encoding, but how do you do it?


You will need to use fork=yes to execute JUnit in a separate JVM.

As it is, file.encoding is being inherited from Ant's JVM and is not overridden by your jvmarg.

See the documentation for jvmarg in the JUnit Task manual page:

If fork is enabled, additional parameters may be passed to the new VM via nested elements.

0

精彩评论

暂无评论...
验证码 换一张
取 消