1

我们正在尝试使用 matcher 使用 ScalaMock 和 ScalaTest 运行测试should be。代码如下:

import org.junit.runner.RunWith
import org.scalamock.scalatest.MockFactory
import org.scalatest._
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class ExampleSpec extends FlatSpec with MockFactory with Matchers {

  "A turtle" should "say hello!" in {

    val m = mock[Pluto]
    val turtle = new Turtle(m)

    (m.say _).expects(15).returns("ciao 15")

    //assert(turtle.ciao === "ciao 15")
    turtle.ciao should be ("ciao 15")
  }

这是我们在 gradle 中的导入(它是一个混合项目 java+scala):

testCompile 'org.scalamock:scalamock-scalatest-support_2.10:3.0.1',
        'junit:junit:4.11',
        'de.flapdoodle.embed:de.flapdoodle.embed.mongo:1.42',
        "org.hamcrest:hamcrest-core:${hamcrestVersion}",
        "org.hamcrest:hamcrest-library:${hamcrestVersion}",
        "org.jmock:jmock:${jmockVersion}"
testCompile("org.jmock:jmock-junit4:${jmockVersion}") {
    exclude group: "junit"
}

我们遇到的错误是:

[ant:scalac] /Users/dierre/IdeaProjects/sitecustomizer/src/test/scala/org/eianni/sitecustomizer/ExampleSpec.scala:20: error: not found: type Matchers
[ant:scalac] class ExampleSpec extends FlatSpec with MockFactory with Matchers {
[ant:scalac]                                                          ^
[ant:scalac] /Users/dierre/IdeaProjects/sitecustomizer/src/test/scala/org/eianni/sitecustomizer/ExampleSpec.scala:30: error: not found: value be
[ant:scalac]     turtle.ciao should be ("ciao 15")
[ant:scalac]                        ^
[ant:scalac] two errors found

非常感谢你的帮助。

4

0 回答 0