ScalaTest Matchers 与 MustMatchers 的区别

标签 scala scalatest matcher

似乎对于最新版本的 ScalaTest,我们有两个匹配器,一个是Matchers(之前的ShouldMatchers)和MustMatchers

这两者之间的真正区别是什么?是团队可以选择的那种风格吗?

此外,shouldBeshouldBe

之间的任何区别

最佳答案

唯一的区别是单词 - 引用 t he 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 所做的工作)。有时看起来这意味着分配的对象更少 - 其他时候,采取相同的步骤,但“应该”和“应该”都在一次通过中注册。据我所知,行为(至少在日常编写测试中)没有区别,只是你在风格上更喜欢哪一种。

关于ScalaTest Matchers 与 MustMatchers 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32353662/

相关文章:

案例类列表中的Scalatest Double等价

Scala 测试 : Replace function implementation

java - 如何使用匹配器从字符串中拉出 double

java - 如何规范化除变音符号之外的所有特殊字符?

scala - StringOps.split(String,Int)中第二个参数的含义

scala - 如何使用scala-time?

android - 使用 scalatest + robolectric

java - 当特定对象特定字段的实例通过时如何 stub 方法?

scala - Scala 解释器 (REPL) 准确打印什么(使用 Map 和 HashMap 进行演示)?

scala - Maven-shade-plugin是否可以与scala类一起使用?