我有一个在大多数机器上运行良好的单元测试,但一个 ubuntu 盒子似乎无法比较特殊字符“?”。字符本身应该是 â。在我的机器上,Eclipse 控制台正常显示我们应该使用哪种编码以确保其有效。
The extracted text was wrong expected:<...tons. Il jette le bl[?me sur ....
but was:<...tons. Il jette le bl[?me sur .....
该测试是使用 Maven 2 使用 java 1.7 在 Eclipse Juno 中运行的
有人有想法吗...?
编辑:
此行为仅在通过 Maven 测试运行单元测试时才会出现,而在执行 Run As Junit 测试时不会出现...在 Maven 配置中,我们有
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
它是为 Maven 用户设置和模块的 pom.xml 文件中设置的。
最佳答案
尝试将UTF-8编码设置为maven-compiler-plugin
里面<build>
您的 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>
关于java - Junit 在法语字符串断言上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13918661/