DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Release of FakeSmtp-Junit-Runner

Release of FakeSmtp-Junit-Runner

The fakesmtp-junit-runner library is a JUnit extension which allows you to write integration tests where an SMTP server is required. Learn how to implement it here.

Sylvain Leroy user avatar by
Sylvain Leroy
CORE ·
May. 27, 17 · Tutorial
Like (2)
Save
Tweet
Share
4.53K Views

Join the DZone community and get the full member experience.

Join For Free

Today, I released a new library to help developers to write integration tests with mail servers.

The library has been released on GitHub and Maven Central.

fakesmtp-junit-runner

fakesmtp-junit-runner can be found on GitHub.

Part of the source code of this library has been modified and adapted from the project of FakeSmtp. I want to thank him since his project inspired me the creation of that library.

This library is an extension to JUnit to allow developers to write integration tests where an SMTP server is required.

The how-to is quite simple:

  • Insert the @Rule in your integration tests.
  • a Fake SMTP Server will start.
  • You can send mail on it.
  • You can control the mailbox.
  • Write your own assertions to check mail.

Installation

The project requires JUnit 4.11 or higher. It also requires SLF4J API presents in the classpath. I did not bundle them in the library to avoid conflicts.

To use it, adds the library to your Maven or Gradle config script:

For Maven:

          < dependency > < groupId > com.github.sleroy < /groupId>          <artifactId>fakesmtp-junit-runner</artifactId > < version > 0.1 .1 < /version>          <scope>test</scope > < /dependency>

For Gradle:

          testCompile "com.github.sleroy:fakesmtp-junit-runner:0.1.1"        

Usage

Step 1:

Create a JUnit test:

          public class SmtpSendingClassTest & #123;                              @Test          public void testCase1() &# 123; & #125;                    &# 125;

Step 2:

Add the new JUnit rule with its configuration:

          public class SmtpSendingClassTest &#123;                    @Rule          public FakeSmtpRule smtpServer = new FakeSmtpRule(ServerConfiguration.create().port(2525).charset("UTF-8"));                    @Test          public void testCase1() &#123;                    &#125;                    &#125;        

Step 3:

You are ready to use it to control the mailbox or the server state:

          Assert.assertTrue(smtpServer.isRunning());        


          public class SmtpSendingClassTest &#123;                    @Rule          public FakeSmtpRule smtpServer = new FakeSmtpRule(ServerConfiguration.create().port(2525).charset("UTF-8"));                    @Test          public void testCase1() &#123;          Assert.assertTrue(smtpServer.isRunning());          Assert.assertTrue(smtpServer.mailbox().isEmpty());          &#125;                    &#125;        


Library Release (agency) Testing JUnit Mail (Apple) Apache Maven Integration GitHub Mailbox (application)

Published at DZone with permission of Sylvain Leroy. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Required Knowledge To Pass AWS Certified Data Analytics Specialty Exam
  • Explainer: Building High Performing Data Product Platform
  • Simulating and Troubleshooting StackOverflowError in Kotlin
  • Essential Mobile App Security Tips for Coders in 2023: Make Your App Unhackable

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: