gpt4 book ai didi

unit-testing - 在 ScalaTest 中 `should` 、 `can` 、 `must` 之间有什么区别

转载 作者:行者123 更新时间:2023-12-03 11:27:59 27 4
gpt4 key购买 nike

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

只需阅读 the docs到目前为止,我一直无法弄清楚 can 之间是否存在任何实质性差异。 , shouldmust条款 FlatSpec .

特别是,我想知道是否是 must失败的处理方式与 should 完全不同一个 - 或者它只是使测试更好地自我记录的“语法糖”。

最佳答案

shouldmust语义相同 .但这与更好的文档无关,这基本上取决于个人风格偏好 (例如,我更喜欢 must)。

can有点不同 .您不能 (nomen omen) 直接将它用作匹配器,它只能在测试描述符中使用。引自 FlatSpec :

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 two corresponding 夹具类)

请注意,在短时间内(我认为在 ScalaTest 2.0.x 中),使用 must已弃用,但是,在 2.1.0 中,决定 has been reverted :

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.

关于unit-testing - 在 ScalaTest 中 `should` 、 `can` 、 `must` 之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22242172/

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