Skip to content

Instantly share code, notes, and snippets.

@gakuzzzz
Last active October 26, 2018 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gakuzzzz/aa223b541dda9f3e7329ef5137470735 to your computer and use it in GitHub Desktop.
Save gakuzzzz/aa223b541dda9f3e7329ef5137470735 to your computer and use it in GitHub Desktop.
Mock/Stub 切り替え

実装

class HogeService {
  val mailer: MailSender = new MailSender()
  
  def foo(): Bar = {
    ...
    mailer.send(mail)
    ...
  }
}

テスト

class HogeServiceSpec {

  val target: HogeService = new HogeService {
    override val mailer = mock[MailSender]
  }
  
  it("なんかのテストするぜ") {
    ...
    assert(target.foo() === expected)
  }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment