# How to stub an interface in test-case?
Include scalamock library dependency i.e.
"org.scalamock" %% "scalamock-scalatest-support"in the project's custom.sbtExtend the test-suite to implement
MockFactoryinterface.grab the stub using keyword
stubimport org.scalamock.scalatest.MockFactory class CreateCommandTestSuite extends FunSuite with SmilePerTest with MockFactory { val lotteryDomainStub = stub[LotteryDomainLogic] ... }set the Binder for the test-case by binding the stub to the testcase name
setBinderFor("create first lottery", bind[LotteryDomainLogic].toInstance(lotteryDomainStub)) test("create first lottery", Tag("create"), ptest) { ... }Inside the testcase provide the stub implementation:
For example, in order to make the api
isOpenToRunreturn true when you pass lottery name as "TestLottery" :test("create first lottery", Tag("create"), ptest) { (lotteryDomainStub.isOpenToRun _).when("TestLottery").returns(true) ... }Note: You can also use wildcards like * inside when