scala
libraryDependencies += "org.scalamock" %% "scalamock" % "4.4.0" % Test
scala
import org.scalamock.scalatest.MockFactory
import org.scalatest.{FlatSpec, Matchers}
scala
class MyTest extends FlatSpec with Matchers with MockFactory {
it should "simulate a method call" in {
val mockObj = mock[MyClass]
(mockObj.myMethod _).expects().returns("mocked result")
val result = mockObj.myMethod()
result should be("mocked result")
}
// ...
}
class MyClass {
def myMethod(): String = {
// Some implementation
}
}