5

我有一个非常简单的测试,我正在尝试模拟一个特征。测试甚至没有运行,它失败并出现初始化错误:java.lang.IllegalArgumentException:需求失败:你记得使用 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 回答