Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Junit 单元测试被三个问号所迷惑_Junit_Hamcrest - Fatal编程技术网

Junit 单元测试被三个问号所迷惑

Junit 单元测试被三个问号所迷惑,junit,hamcrest,Junit,Hamcrest,我正在编写一些JUnit,并进行此检查,比较两个HashMap的键和值 Iterator<Map.Entry<String, String>> it = expected.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next(); assertTrue("C

我正在编写一些JUnit,并进行此检查,比较两个HashMap的键和值

Iterator<Map.Entry<String, String>> it = expected.entrySet().iterator();
while (it.hasNext()) {
    Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
    assertTrue("Checks key exists", actual.containsKey(pairs.getKey()));
    assertThat("Checks value", actual.get(pairs.getKey()), equalTo(pairs.getValue()));
}

我检查了数据,数据是正确的。看来是三重的?不知怎么搞砸了什么。有人知道为什么会被绊倒吗?对我来说,这似乎很基本,它甚至不是hamcrest搞砸了,而是实际的断言。

您有一个编码冲突。这可能以许多不同的方式表现出来,但通常是由于没有全面实施一致的编码

假设您在某处使用UTF-8

  • 如果使用Maven,请将属性
    project.build.sourceEncoding
    设置为
    UTF-8
    。 其他构建系统肯定会有指定代码和资源文件编码的选项
  • 如果使用IO读取(或写入),请始终指定编码。例如,从文件读取时:
    InputStream is=newfileinputstream(文件),“UTF8”)

简言之,找到任何用于编码的构建系统设置,以及读取文本时涉及IO的任何点,并确保设置了所需的编码。

数据来自何处?从文件中?检查编码。它来自oracle数据库。它映射到字符串的事实应该使它们相等,不是吗?将加载的值打印到控制台或写入日志。一定有编码问题。我认为JUnit/Hamcrest不是问题所在。旁注:您不需要强制转换
Map.Entry pairs=(Map.Entry)it.next()。这些看起来像不可打印的字符,而不是问号。尝试打印它们的Unicode值。
java.lang.AssertionError: Checks value
Expected: "Member???s "
     but: was "Member���s "
    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)