gpt4 book ai didi

junit - hamcrest-library Matchers 和 hamcrest-core CoreMatchers 之间的区别

转载 作者:行者123 更新时间:2023-12-03 05:34:23 26 4
gpt4 key购买 nike

看起来 hamcrest org.hamcrest.Matchers 类与 org.hamcrest.CoreMatchers 非常相似(尽管它看起来像 Matchers有更多的)。为什么我会选择使用 CoreMatchers(除了看起来类稍微小一些之外),为什么这两个类如此相似?

最佳答案

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

你应该使用哪个?我毫无问题地静态导入后者的所有内容。也许编译时间可能会稍微长一些,但这对我来说从来都不是问题。除了 JUnit 导入之外,我还将其放在单元测试的顶部:

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

这为测试方法提供了最佳的可读性。

关于junit - hamcrest-library Matchers 和 hamcrest-core CoreMatchers 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10932941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com