hamcrest-library Matchers和hamcrest-Core CoreMatchers之间的区别 [英] Difference between hamcrest-library Matchers and hamcrest-core CoreMatchers

查看:416
本文介绍了hamcrest-library Matchers和hamcrest-Core CoreMatchers之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来hamcrest org.hamcrest.Matchers类与org.hamcrest.CoreMatchers非常相似(尽管Matchers具有更多功能).为什么我选择使用CoreMatchers(看起来好像类稍小些),为什么这两个类是如此相似?

It looks like the hamcrest org.hamcrest.Matchers class is very similar to org.hamcrest.CoreMatchers (though it looks like Matchers has more). Why would I choose to use CoreMatchers (other than it looks like the class is slightly smaller), and why are these two classes so similar?

推荐答案

Hamcrest匹配器分为几个模块. 核心"包括构建其他匹配器所需的最基本的匹配器和抽象类. org.hamcrest.CoreMatchers仅包括这些匹配器的工厂方法.其他匹配器位于库"模块中,按它们匹配的对象类型分组,并且是可选的. org.hamcrest.Matchers包括两组匹配器.

The Hamcrest matchers are split into several modules. The "core" includes the most basic matchers and abstract classes required for building other matchers. org.hamcrest.CoreMatchers includes the factory methods for just these matchers. The other matchers are in the "library" module grouped by the types of objects they match and are optional. org.hamcrest.Matchers includes both sets of matchers.

您应该使用哪个?我从后者静态导入所有内容,没有任何麻烦.也许编译时间可能会花费更长的时间,但这对我来说从来不是一个问题.除了JUnit导入之外,我将其放在单元测试的顶部:

Which should you use? I statically import everything from the latter without any trouble. Perhaps the compile times might take slightly longer, but that's never been an issue for me. I put this at the top of my unit tests in addition to the JUnit imports:

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

这在测试方法中提供了最佳的可读性.

This gives the best readability in the test methods.

这篇关于hamcrest-library Matchers和hamcrest-Core CoreMatchers之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆