Junit fails on french string assertion

霸气de小男生 提交于 2019-12-22 14:03:55

问题


I have a unit test that works well on most machine but one ubuntu box seems to not be able to compare special characters "?". The character itself should be â. On my machine the eclipse console displays it normally which encoding should we be playing with to ensure that this works.

The extracted text was wrong expected:<...tons. Il jette le bl[?me sur ....

but was:<...tons. Il jette le bl[?me sur .....

The test is ran within Eclipse Juno using Maven 2 using java 1.7

Does anyone have an idea...?

EDIT:

This behavior is only seen when running the unit test through Maven test and not when performing a run As Junit test... In the maven configuration we have the

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

Which is set for both maven user settings and within the module's pom.xml file.


回答1:


Try to put UTF-8 encoding to maven-compiler-plugin inside <build> section in your pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.5.1</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
    <encoding>UTF-8</encoding>
  </configuration>
</plugin>



回答2:


We manage to fix the issue with @Slawomir Jaranowski solution to THIS issue.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
  </configuration>
</plugin>



回答3:


I recently had a problem with Unicode in JUnit. You can try using the escaped notation of the offending Unicode character in the JUnit test, or in the program itself.

In your case, try using /u0032 Instead of using â.



来源:https://stackoverflow.com/questions/13918661/junit-fails-on-french-string-assertion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!