我正在编写使用jUnit作为测试运行器的黄瓜测试用例。如果两个对象都有相同的元素,我使用方法断言为真。
assertThat(obj1).containsOnlyElementsOf(obj2)
但是,即使两个对象具有完全相同的元素和相同的值,它也不会返回true。这是堆栈跟踪。
java.lang.AssertionError:
Expecting:
<[com.solambda.kronos.timesheet.dto.TimesheetListRowDto@e12becd7,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@4543a8b3,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@c08e2719,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@d298d9da]>
to contain only:
<[com.solambda.kronos.timesheet.dto.TimesheetListRowDto@6276a018,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@ed39d0fe,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@7bda09e9,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@673947a0]>
elements not found:
<[com.solambda.kronos.timesheet.dto.TimesheetListRowDto@6276a018,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@ed39d0fe,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@7bda09e9,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@673947a0]>
and elements not expected:
<[com.solambda.kronos.timesheet.dto.TimesheetListRowDto@e12becd7,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@4543a8b3,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@c08e2719,
com.solambda.kronos.timesheet.dto.TimesheetListRowDto@d298d9da]>
at com.solambda.kronos.timesheet.steps.TimesheetSteps.i_get_the_following_timesheet s(TimesheetSteps.java:806)
at ✽.Then I get the following timesheets: (com/solambda/kronos/timesheet/Worker_list.feature:43)
有没有人遇到过类似的问题。如果我遗失某些东西或者没有正确地做事,请告诉我。
答案 0 :(得分:0)
我假设您使用assertj-core
作为方法containsOnlyElementsOf
的库!?
此方法containsOnlyElementsOf
确实检查迭代物是否具有相同的对象,而不仅仅是它们相等!