I have a very simple test and I'm trying to mock a trait. The test does not even run, and it fails with the initialization error: java.lang.IllegalArgumentException: requirement failed: Have you remembered to use withExpectations?
Here is my very simple test:
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)
}
}
}
you need to call resetMocks / resetExpectations before running the test, the best way to do that is (ScalaTest way):
class TurtleSpec extends FunSpec with MockFactory with ProxyMockFactory with BeforeAndAfter {
before {
resetMocks()
resetExpectations()
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With