2
我使用specs2,我的理解是must
和should
是等效的(请参阅What is the difference between should and must in scala testing?),使用其中一个或另一个只是个人偏好。字符串Specs2比较不应该与应该
但是,使用must
作品比较字符串,下面的测试时:
import org.specs2.mutable._
class StringEqualWithMust extends Specification {
"string comp " should {
"abc" must beEqualTo("abc")
}
}
但使用相同的测试should
不会编译:
import org.specs2.mutable._
class StringEqualWithShould extends Specification {
"string comp " should {
"abc" should beEqualTo("abc")
}
}
的编译错误是:
StringEqualWithShould.scala:7: overloaded method value should with alternatives:
[error] (fs: => org.specs2.specification.core.Fragments)(implicit p1: org.specs2.control.ImplicitParameters.ImplicitParam1)org.specs2.specification.core.Fragments <and>
[error] (f: => org.specs2.specification.core.Fragment)org.specs2.specification.core.Fragment
[error] cannot be applied to (org.specs2.matcher.BeEqualTo)
[error] "abc" should beEqualTo("abc")
[error] ^
[error] one error found
为什么之间有差异和should
比较字符串?
我使用SBT 0.13.8,斯卡拉2.12.0和specs2 3.8.6
的可变规格的预期的结构是'should'(>''>>)>'in'和'必须'与匹配器 – cchantep
您使用的是哪个版本的specs2?你可以用'3.8.6'来试试吗? – Eric
与3.8.6版本相同 – obourgain