在 ScalaTest 中,`should`、`can`、`must` 之间有什么区别吗? [英] In ScalaTest is there any difference between `should`, `can`, `must`

查看:73
本文介绍了在 ScalaTest 中,`should`、`can`、`must` 之间有什么区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始使用 ScalaTest,我非常喜欢它.

Just started using ScalaTest and I quite like it.

仅通过阅读文档我至今无法弄清楚是否有任何实质性em> FlatSpeccanshouldmust 子句之间的区别.

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.

推荐答案

shouldmust 在语义上是相同的.但这与更好的文档无关,基本上只是个人风格偏好(例如,我更喜欢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.为了例如,而不是它应该流行...,你可以写它必须"流行...或者它可以弹出....

Note: you can use must or can as well as should in a FlatSpec. For example, instead of it should "pop..., you could write it must "pop... or it can "pop....

(同样适用于 WordSpec两个 对应夹具类)

(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.

Resurrected MustMatchers in package org.scalatest. Changed deprecation warning for org.scalatest.matchers.MustMatchers to suggest using org.scalatest.MustMatchers instead of org.scalatest.Matchers, which was the suggestion in 2.0. Apologies to must users who migrated to should already when upgrading to 2.0.

这篇关于在 ScalaTest 中,`should`、`can`、`must` 之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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