我有一个简单的电子邮件类(我正在使用Emailer插件):
public class Email {
public static boolean sendEmail(final String to, final String body, final String subject) {
MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
mail.setSubject(subject);
mail.addRecipient(to);
try {
mail.send(body);
Logger.info(String.format("Sucessfully sent an email to %s", to));
return true;
} catch (Exception e) {
Logger.info(String.format("An error occured when trying to send email to %s: %s", to, e.getStackTrace()));
}
return false;
}
}
我尝试使用测试类测试它:
public class EmailTest {
@Test
public void sendEmail() {
running(fakeApplication(), new Runnable() {
public void run() {
boolean status = Email.sendEmail("my_email", "hello", "subject demo");
assertThat(status).equals("true");
}
});
}
}
我跑:play test
但我收到了:
[info] EmailTest
[error] Test EmailTest.sendEmail failed: null
[error] at utils.Email.sendEmail(Email.java:12)
[error] at EmailTest$1.run(EmailTest.java:15)
[error] at play.test.Helpers.running(Helpers.java:294)
[error] at EmailTest.sendEmail(EmailTest.java:13)
[error] ...
[info] x EmailTest.sendEmail
[info]
[info]
[info] Total for test EmailTest
[info] Finished in 11.073 seconds
[info] 1 tests, 1 failures, 0 errors
[error] Failed: : Total 1, Failed 1, Errors 0, Passed 0, Skipped 0
你能告诉我我做错了什么吗?找出失败的原因并没有更明确的例外......
答案 0 :(得分:1)
错误的发生不是因为测试工作流程,而是因为我忘了添加它:
1500:com.typesafe.plugin.CommonsMailerPlugin
播放.plugins。