问题描述
刚开始使用 ScalaTest,我非常喜欢它.
Just started using ScalaTest and I quite like it.
仅通过阅读文档我至今无法弄清楚是否有任何实质性em> FlatSpec
的 can
、should
和 must
子句之间的区别.
By just reading the docs I have thus far been unable to figure out whether there is any substantial difference between the can
, should
and must
clauses for a FlatSpec
.
特别是,我想知道 must
失败是否与 should
失败有任何不同 - 或者它只是语法糖",使测试更好-记录.
In particular, I'm wondering whether a must
failure is treated any differently from a should
one - or it's just "syntactic sugar" to make the tests better self-documented.
推荐答案
should
和 must
在语义上是相同的.但这与更好的文档无关,基本上只是个人风格偏好(例如,我更喜欢must
).
should
and must
are the same semantically. But it's not about better documentation, it's basically just down to personal stylistic preference (I prefer must
for example).
can
有点不同.您不能 (nomen omen) 直接将它用作匹配器,它只能在测试描述符中使用.引用自 FlatSpec
:
注意:您可以在 FlatSpec 中使用 must 或 can 以及 should.为了例如,而不是它应该流行...,你可以写它必须"流行...或者它可以弹出....
(the same applies for WordSpec
and the two corresponding fixture classes)
请注意,在短时间内(我认为在 ScalaTest 2.0.x 中),不推荐使用 must
,但是,在 2.1.0 中,决定 已还原:
Note that for a short time (in ScalaTest 2.0.x I think), the use of must
was deprecated, however, in 2.1.0, the decision has been reverted:
在 org.scalatest 包中复活了 MustMatchers.更改弃用警告 org.scalatest.matchers.MustMatchers 建议使用org.scalatest.MustMatchers 而不是 org.scalatest.Matchers,后者是 2.0 中的建议.向迁移到的必须用户道歉应该已经升级到 2.0.
这篇关于在 ScalaTest 中,`should`、`can`、`must` 之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!