我的大部分测试都使用hamcrest,但遇到了一个问题,它无法测试对象图中下一层的属性。下面是我的测试用例的片段finalListfoos=fooRepository.findAll(spec);assertThat(results,is(notNullValue()));assertThat(results,hasItem(hasProperty("id.fooID1",equalTo("FOOID1"))));所以在这里我想检查foos列表中是否有属性id.fooID1equla到FOOID1。在这里我要向下一级检查我的嵌套属性。这目前在hamcrest中不起作用,我得到以下信息错
我正尝试在SpringMVCController中实现一个方法的单元测试,如下所示:@TestpublicvoidtestGetProfile(){PersonmockPerson=newPerson();mockPerson.setPersonId(1);mockPerson.setName("MrBrown");mockPerson.setAddress("Somewhere");mockPerson.setTelephone("1234567890");mockPerson.setEmail("brown@brown.com");when(mockPersonService.ge
我有一个Java方法,它在Mongo集合的两个字段上创建索引。我应该获取集合的索引信息,然后检查索引的名称和字段是否正确。为此编写集成测试的最干净的方法是什么?使用自定义Hamcrest匹配器查看索引是否在集合中有意义吗? 最佳答案 Spring与MongoTemplate#indexOps(Stringcollection)你可以获取IndexInfo的列表,表示MongoDB集合的索引。由于这是一个常规列表,您可以使用hasItem(MatcheritemMatcher)的组合来进行断言。和hasProperty(Stringp
我想知道一个属性是否存在于一个类中,我试过这个:publicstaticboolHasProperty(thisobjectobj,stringpropertyName){returnobj.GetType().GetProperty(propertyName)!=null;}我不明白为什么第一个测试方法没有通过?[TestMethod]publicvoidTest_HasProperty_True(){varres=typeof(MyClass).HasProperty("Label");Assert.IsTrue(res);}[TestMethod]publicvoidTest_H
我想知道一个属性是否存在于一个类中,我试过这个:publicstaticboolHasProperty(thisobjectobj,stringpropertyName){returnobj.GetType().GetProperty(propertyName)!=null;}我不明白为什么第一个测试方法没有通过?[TestMethod]publicvoidTest_HasProperty_True(){varres=typeof(MyClass).HasProperty("Label");Assert.IsTrue(res);}[TestMethod]publicvoidTest_H
importstaticorg.hamcrest.MatcherAssert.assertThat;importstaticorg.hamcrest.Matchers.hasItem;importstaticorg.hamcrest.Matchers.equalTo;assertThat(actual,hasItem(hasProperty("id",equalTo(1L))));其中actual是一个ID为Long的POJO。我明白了,ThemethodassertThat(T,Matcher)inthetypeMatcherAssertisnotapplicableforthear