테스트하는 동안 Play 2.3에서 play.api.libs.mailer.MailerPlugin을 위조하여 전송할 이메일을 확보 할 수 있습니다. 어떻게해야합니까?테스트 중에 MailerPlugin.send를 위조하여 보낸 이메일을받을 수 있습니까?
가장 쉬운 어쩌면 최고의 하나 : 부작용 분리 기능, 작성을 분리
응용 프로그램 코드
package services
import play.api.libs.mailer._
import play.api.Play.current
object EmailService {
def sendUserNotification(to: String, subject: String, content: String): Unit = {
val email = Email(
"subject",
"Admin <[email protected]>",
Seq(to),
bodyHtml = Some(s"""<html>
| <body>
| $content
| </body>
| </html>
| """.stripMargin)
)
// Should like to fake this from tests, but how?
MailerPlugin.send(email)
}
}
테스트 코드
object Test {
def testEmail(): Unit = {
// How do I get hold of the sent email?
EmailService.sendUserNotification("[email protected]", "Test", "Testing...")
}
}
당신은 가짜 의미는'MailerPlugin' 당신은하지 않습니다? 필자가 언급 한 기술을 통해 가짜'MailerPlugin'을'FakeApplication'에 주입하는 결과를 낳았습니다. 이것이 내가 원하는 것입니다. 왜냐하면 테스트에서 가능한 한 많이 스텁을 피하기 때문입니다. – aknuds1
정확히 무엇을 의미합니까! :) – johanandren