5

非常に単純なテストがあり、特性をモックしようとしています。テストは実行されず、初期化エラーで失敗します: java.lang.IllegalArgumentException: requirements failed: Have you remember to use withExpectations?

これが私の非常に簡単なテストです:

import org.scalatest._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.matchers.ShouldMatchers
import org.scalamock.ProxyMockFactory
import org.scalamock.scalatest.MockFactory

@RunWith(classOf[JUnitRunner])
class TurtleSpec extends FunSpec with MockFactory with ProxyMockFactory {
  trait Turtle {
    def turn(angle: Double)
  }

  val m = mock[Turtle]
  m expects 'turn withArgs (10.0)

  describe("A turtle-tester") {
    it("should test the turtle") {
      m.turn(10.0)
    }
  }
}
4

1 に答える 1

1

テストを実行する前に resetMocks / resetExpectations を呼び出す必要があります。これを行う最善の方法は (ScalaTest の方法) です。

class TurtleSpec extends FunSpec with MockFactory with ProxyMockFactory with BeforeAndAfter {

  before {
    resetMocks()
    resetExpectations()
  }

  ...
}
于 2013-06-25T15:51:20.620 に答える