Introducing Java tips GreenMail to Junit5

Introducing GreenMail to Junit5

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.

Sample source

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?

Summary

You can use GreenMail with JUnit 5 without any problem.

Recommended Posts

Introducing Java tips GreenMail to Junit5
Java tips, tips
My note: Introducing Java to Ubuntu
Java Tips
[Java] Introduction to Java
Introduction to java
[Java] How to test for null with JUnit
Changes from Java 8 to Java 11
Sum from Java_1 to 100
Migrate from JUnit 4 to JUnit 5
Introducing CircleCI to Rails
Introducing Bootstrap to Rails 5
Introducing Bootstrap to Rails !!
How to make Java unit tests (JUnit & Mockito & PowerMock)
[Java] Connect to MySQL
Java JUnit brief note
[For newcomers] Introducing JUnit
Kotlin's improvements to Java
Introducing New Relic to Java apps running on Heroku
From Java to Ruby !!
How to use JUnit 5
Introduction to java command
Tips around the sample to release Java Lambda on CodePipeline
[Java] I want to test standard input & standard output with JUnit
[Java] How to use Map
[Java] JUnit4 test case example
How to lower java version
Migration from Cobol to JAVA
[Java] How to use Map
Convert Java Powerpoint to XPS
Java adds table to PDF
Java tips --StaticUtility class modifier
How to uninstall Java 8 (Mac)
Introducing AWS CLI to CentOS 7
Java to play with Function
Java --How to make JTable
Introducing past nvidia-driver to Ubuntu
How to use JUnit (beginner)
New features from Java7 to Java8
How to write java comments
How to use java class
Introduction to JUnit (study memo)
[Java] How to use Optional ②
Connect from Java to PostgreSQL
[Java] How to use removeAll ()
[Java] How to display Wingdings
Shell to kill Java process
How to use Java Map
How to set Java constants
Connect to DB with Java
Connect to MySQL 8 with Java
[java] Reasons to use static
Java tips --Spring execution Summary
How to write Junit 5 organized
How to use Java variables
[Java] Tips for writing source
[Java] Introduction to Stream API
Java8 to start now ~ Optional ~
How to convert Java radix
[Java] Convert ArrayList to array
Introducing JITSI MEET to CentOS 8