问题描述
我有两个 HashMap< Integer,Question>
地图,我想比较。 问题
在这种情况下是我写的Javabean。
如何断言 HashMap
是否相等?在这种情况下,等于意味着 HashMap
包含完全相同的问题
bean?
如果它在所有相关的,我正在使用JUnit写一个单元测试。解决方案我最终最终使用它完美地用于单元测试目的。
for(Map.Entry< Integer,Question& questionMap.entrySet()){
assertReflectionEquals(entry.getValue(),expectedQuestionMap.get(entry.getKey()),ReflectionComparatorMode.LENIENT_ORDER);
}
这包括调用 assertReflectionEquals()
从 unitils
包。
< dependency>
< groupId> org.unitils< / groupId>
< artifactId> unitils-core< / artifactId>
< version> 3.3< / version>
< scope> test< / scope>
< / dependency>
I have two HashMap<Integer, Question>
maps that I would like to compare. Question
in this case is a Javabean I have written.
How do I assert that both HashMap
are equal? In this scenario, equal means that both HashMap
contains exactly the same Question
bean?
If it's at all relevant, I am writing a unit test using JUnit.
Here is the solution I eventually ended up using which worked perfectly for unit testing purposes.
for(Map.Entry<Integer, Question> entry : questionMap.entrySet()) {
assertReflectionEquals(entry.getValue(), expectedQuestionMap.get(entry.getKey()), ReflectionComparatorMode.LENIENT_ORDER);
}
This involves invoking assertReflectionEquals()
from the unitils
package.
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-core</artifactId>
<version>3.3</version>
<scope>test</scope>
</dependency>
这篇关于我如何断言两个HashMap与Javabean值相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!