gpt4 book ai didi

junit - 在 hashmap JUnit 中断言键

转载 作者:行者123 更新时间:2023-12-04 00:34:42 24 4
gpt4 key购买 nike

我认为这会很容易,但谁能告诉我如何测试 HashMap 以查看它在 JUnit 中是否有一些值(value)?

assertThat(myMap, ??);

我试过类似的方法:

assertThat(myMap, hasEntry("Key", notNullValue()));

...但是我无法编译它,因为我对 hasEntry 和 notNullValue() 的导入是正确的。有谁知道对他们来说正确的 import pkg 应该是什么?

最佳答案

你在寻找 hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher) .

底层实现在 IsMapContaining 中但,与 Hamcrest 中的大多数匹配器一样,它也可以通过 org.hamcrest.Matchers 找到, 在 hamcrest-library .

否则,你的语法是正确的,Matchers还定义了 notNullValue() .

关于junit - 在 hashmap JUnit 中断言键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26045778/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com