4

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?

Carlos
  • 2,503
  • 26
  • 29
  • See also: http://stackoverflow.com/questions/1339352/how-do-i-set-dfile-encoding-within-ants-build-xml and http://stackoverflow.com/questions/1686271/how-do-i-set-file-encoding-for-a-junit-test-in-ant – martin clayton Jul 07 '11 at 15:19

1 Answers1

6

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.

ewan.chalmers
  • 16,145
  • 43
  • 60
  • Thank you, that did the trick. I was kinda expecting the command line parameter to affect Ant's JVM, but I suppose not. – Carlos Jul 08 '11 at 07:47
  • I would have expected so too. I can only guess that you didn't pass it the "right way". Maybe `ant -Dfile.encoding=UTF-8 run_tests` or include it in ANT_OPTS? – ewan.chalmers Jul 08 '11 at 07:56