I've heard that ScalaMock supported the feature of mocking singleton objects with method mockObject
. But it was removed from ScalaMock 3.
But if you had a trait instead of object you could use ScalaMock 4 with ScalaTest, namely using proxy.MockFactory
:
import java.time.LocalDate
import org.scalamock.scalatest.proxy.MockFactory
import org.scalatest.FunSuite
class FooTest extends FunSuite with MockFactory {
test("it should return local date") {
val launchDate: LocalDate = LocalDate.of(2017, 6, 15)
val m = mock[FooService]
m.expects('launchDate)().returning(launchDate)
assertResult(launchDate)(m.launchDate)
}
}
build.sbt
dependencies:
libraryDependencies ++= Seq("org.scalactic" %% "scalactic" % "3.0.5",
"org.scalatest" %% "scalatest" % "3.0.5" % Test,
"org.scalamock" %% "scalamock" % "4.1.0" % Test)