Java hasItems断言错误,iterable包含
我试图断言一个列表返回我需要的值,但是断言失败了,我不知道为什么差值相等Java hasItems断言错误,iterable包含,java,assertion,hamcrest,serenity-bdd,Java,Assertion,Hamcrest,Serenity Bdd,我试图断言一个列表返回我需要的值,但是断言失败了,我不知道为什么差值相等 theActorInTheSpotlight().should(seeThat(Elmenu.menu(SegurosVolutariosUi.CAMPOS_FORMULARIO_SEGUROS_VOLUTARIOS), contains(etiquetasFormulario))) java.lang.AssertionError: 应为:iterable包含[] 但是:第0项:是“Aseguradora” 我认为失败
theActorInTheSpotlight().should(seeThat(Elmenu.menu(SegurosVolutariosUi.CAMPOS_FORMULARIO_SEGUROS_VOLUTARIOS), contains(etiquetasFormulario)))
java.lang.AssertionError:
应为:iterable包含[]
但是:第0项:是“Aseguradora”
我认为失败的原因是您的方法试图比较整个集合,这并不等于。
如果要检查单个/多个项目是否存在,可以使用hasItem匹配器
// direct check for a single value
theActorInTheSpotlight().should(seeThat(Elmenu.menu(SegurosVolutariosUi.CAMPOS_FORMULARIO_SEGUROS_VOLUTARIOS), hasItem("Aseguradora")))
// or just make an array with items from the list
theActorInTheSpotlight().should(seeThat(Elmenu.menu(SegurosVolutariosUi.CAMPOS_FORMULARIO_SEGUROS_VOLUTARIOS), hasItems(etiquetasFormulario.toArray(new String[0]))))
etiquetasFormulario是一个列表,menu方法返回一个列表
// direct check for a single value
theActorInTheSpotlight().should(seeThat(Elmenu.menu(SegurosVolutariosUi.CAMPOS_FORMULARIO_SEGUROS_VOLUTARIOS), hasItem("Aseguradora")))
// or just make an array with items from the list
theActorInTheSpotlight().should(seeThat(Elmenu.menu(SegurosVolutariosUi.CAMPOS_FORMULARIO_SEGUROS_VOLUTARIOS), hasItems(etiquetasFormulario.toArray(new String[0]))))