大佬教程收集整理的这篇文章主要介绍了如何在集成测试中测试Mongo索引?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用,@H_203_5@mongoTemplate#indexOps(String
collection)您可以获取的列表IndexInfo
,代表MongoDB集合的索引。由于这是一个常规列表,因此您可以结合使用hasItem(Matcher<?
super T> itemmatcher)
和进行断言hasProperty(String propertyname, Matcher<?>
valueMatcher)
:
final List<IndexInfo> indexes = mongoTemplate.indexOps("myCollection").geTindexInfo();
assertthat(indexes, hasSize(3));
assertthat(indexes, hasItem(hasProperty("name", is("_ID_"))));
assertthat(indexes, hasItem(hasProperty("name", is("index1"))));
assertthat(indexes, hasItem(hasProperty("name", is("index2"))));
assertthat(indexes, hasItem(hasProperty("indexFIElds", hasItem(hasProperty("key", is("fIEld1"))))));
如果您觉得这太难以理解或不方便使用,最好使用自定义的Hamcrest匹配器。
我有一个Java方法,可在Mongo集合的两个字段上创建索引。我应该获取集合的索引信息,然后检查索引的名称和字段是否正确。为此编写集成测试的最干净方法是什么?使用自定义的Hamcrest匹配器查看索引是否在集合中是否有意义?
以上是大佬教程为你收集整理的如何在集成测试中测试Mongo索引?全部内容,希望文章能够帮你解决如何在集成测试中测试Mongo索引?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。