ScalaTest Matchers 与 MustMatchers 的区别
ScalaTest Matchers vs MustMatchers difference
对于最新版本的 ScalaTest,我们似乎有两个匹配器,一个是 Matchers
(之前是 ShouldMatchers)和 MustMatchers
。
这两者之间的真正区别是什么?是团队可以选择的那种风格还是?
此外,shouldBe
和 should be
之间的任何区别
唯一的区别是这个词 - 引用自 the ScalaDocs for MustMatcher
:
Trait MustMatchers
is an alternative to Matchers
that provides the exact same meaning, syntax, and behavior as Matchers
, but uses the verb must instead of should. The two traits differ only in the English semantics of the verb: should is informal, making the code feel like conversation between the writer and the reader; must is more formal, making the code feel more like a written specification.
至于 should be
与 shouldBe
... 这取决于您正在调用 should[Be]
的哪个实例。在所有情况下,shouldBe
都会少执行一个注册步骤(因为它跳过了 be
所做的工作)。有时这看起来意味着分配的对象更少 - 其他时候,采取相同的步骤,但 "should" 和 "be" 都在一次传递中注册。据我所知,行为没有区别(至少在日常编写测试中),只是你更喜欢哪一种风格。
对于最新版本的 ScalaTest,我们似乎有两个匹配器,一个是 Matchers
(之前是 ShouldMatchers)和 MustMatchers
。
这两者之间的真正区别是什么?是团队可以选择的那种风格还是?
此外,shouldBe
和 should be
唯一的区别是这个词 - 引用自 the ScalaDocs for MustMatcher
:
Trait
MustMatchers
is an alternative toMatchers
that provides the exact same meaning, syntax, and behavior asMatchers
, but uses the verb must instead of should. The two traits differ only in the English semantics of the verb: should is informal, making the code feel like conversation between the writer and the reader; must is more formal, making the code feel more like a written specification.
至于 should be
与 shouldBe
... 这取决于您正在调用 should[Be]
的哪个实例。在所有情况下,shouldBe
都会少执行一个注册步骤(因为它跳过了 be
所做的工作)。有时这看起来意味着分配的对象更少 - 其他时候,采取相同的步骤,但 "should" 和 "be" 都在一次传递中注册。据我所知,行为没有区别(至少在日常编写测试中),只是你更喜欢哪一种风格。