When I tried to introduce the mail communication library "GreenMail" for unit testing, I looked it up. There are many samples using @Rule of Junit4, so I was a little worried about what to do with JUnit5. I will summarize it as a memorandum.
The method of using GreenMail with Junit5 for SMTP communication without any problem is as follows.
class SampleTest {
//SMTP communication class (like a virtual server)
private GreenMail smtp =
new GreenMail(new ServerSetup(3025,"localhost",ServerSetup.PROTOCOL_SMTP));
@BeforeEach
void before() {
//Start virtual server
smtp.start();
}
@AfterEach
void after() {
//Virtual server termination
smtp.stop();
}
}
Is it an image of setting up a mail server locally by yourself and explicitly writing the start and end in the source?
You can use GreenMail with JUnit 5 without any problem.
Recommended Posts