3
我試圖按照this doc - scalatest
與scala-mock
嘲笑功能並檢查它是否已被稱爲斯卡拉模擬,MockFactory預計將失敗,並「意外來電」
class AggregateSpec extends FlatSpec with Matchers with MockFactory {
val data = Seq("This", "is", "something", "I", "would", "like", "to", "know")
"combop function" should "BE called for par collection" in {
val mockCombop = mockFunction[Int, Int, Int]
val parData = data.par
val result: Int = parData.aggregate(0)(
seqop = (acc, next) => acc + next.length,
combop = mockCombop
)
result should === (31)
mockCombop.expects(*, *).atLeastOnce()
}
}
至於結果:
> [info] - should BE called for non-par collection *** FAILED *** [info]
> Unexpected call: MockFunction2-1(4, 2) [info] [info] Expected:
> [info] inAnyOrder { [info] [info] } [info] [info] Actual:
> [info] MockFunction2-1(9, 1) [info] MockFunction2-1(2, 4)
> [info] MockFunction2-1(4, 2) [info] MockFunction2-1(5, 4)
> (Option.scala:121)
爲什麼?如何使它通過scalatest + scala-mock?
-
由於DEPS我用:
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.1",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test",
libraryDependencies += "org.scalamock" %% "scalamock-scalatest-support" % "3.5.0"
呀。接得好。唯一的事情就是,「底線」要比底線好得多。 – ses
您可以使用Record-then-Verify樣式,如下所述:http://scalamock.org/user-guide/mocking_style/ –
https://github.com/Sergey80/scala-samples/blob/master/algorithms/的src /測試/階/測試/ AggregateSpec.scala – ses