JUnit Fake SMTP Server Rule

JUnit Rule to create a FakeSmtp server to write mailing integration tests

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

com.github.sleroy
ArtifactId

ArtifactId

fakesmtp-junit-runner
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

JUnit Fake SMTP Server Rule
JUnit Rule to create a FakeSmtp server to write mailing integration tests
Project URL

Project URL

https://github.com/sleroy/fakesmtp-junit-runner
Source Code Management

Source Code Management

https://github.com/sleroy/fakesmtp-junit-runner

Download fakesmtp-junit-runner

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.sleroy/fakesmtp-junit-runner/ -->
<dependency>
    <groupId>com.github.sleroy</groupId>
    <artifactId>fakesmtp-junit-runner</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.sleroy/fakesmtp-junit-runner/
implementation 'com.github.sleroy:fakesmtp-junit-runner:0.1.1'
// https://jarcasting.com/artifacts/com.github.sleroy/fakesmtp-junit-runner/
implementation ("com.github.sleroy:fakesmtp-junit-runner:0.1.1")
'com.github.sleroy:fakesmtp-junit-runner:jar:0.1.1'
<dependency org="com.github.sleroy" name="fakesmtp-junit-runner" rev="0.1.1">
  <artifact name="fakesmtp-junit-runner" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.sleroy', module='fakesmtp-junit-runner', version='0.1.1')
)
libraryDependencies += "com.github.sleroy" % "fakesmtp-junit-runner" % "0.1.1"
[com.github.sleroy/fakesmtp-junit-runner "0.1.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.subethamail : subethasmtp jar 3.1.7
commons-io : commons-io jar 2.5
org.apache.commons : commons-lang3 jar 3.5

test (6)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19
javax.mail : javax.mail-api jar 1.5.6
javax.mail : mail jar 1.4.1
com.sun.mail : javax.mail jar 1.5.6
com.github.nithril : smtp-connection-pool jar 1.2.1

Project Modules

There are no modules declared in this project.

fakesmtp-junit-runner

Build Status

Coverage Status

Javadocs

Important : 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 a SMTP server is required.

The how-to is quite simple :

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

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 :

Creates a JUnit test :

public class SmtpSendingClassTest {


  @Test
  public void testCase1() {

  }

}

Step 2 :

Adds the new Junit rule with its configuration :

public class SmtpSendingClassTest {

  @Rule
	public FakeSmtpRule smtpServer = new FakeSmtpRule(ServerConfiguration.create().port(2525).charset("UTF-8"));

  @Test
  public void testCase1() {

  }

}

Step 3 :

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

Assert.assertTrue(smtpServer.isRunning());
public class SmtpSendingClassTest {

  @Rule
	public FakeSmtpRule smtpServer = new FakeSmtpRule(ServerConfiguration.create().port(2525).charset("UTF-8"));

  @Test
  public void testCase1() {
    Assert.assertTrue(smtpServer.isRunning());
    Assert.assertTrue(smtpServer.mailbox().isEmpty());
  }

}

Versions

Version
0.1.1
0.1.0