public interface FakeEmailServer
Firstly, you need to change you system under test and set the SMTP host and port for it. With this setting, all email communications originated by the system will go to the "fake" email server. (So the system will not send those emails to the real recipients, but you will be able to check them.)
In many cases it is enough to set the mail.smtp.host system property to "localhost", and set
the mail.smtp.port property to the port where we want to run our fake server. But the correct setup depends on
the tested system - contact your developers if you are unsure about it.
Secondly, you need to add a FakeEmailServer instance to your step libraries, with the Inject annotation:
@Inject private FakeEmailServer emailServer;
The server is in session scope, but it controls a singleton SMTP server.
Before you want to use the email server, you need to start it. Call the start(int) method with your selected port number.
Typically you can do this in a before-test block. It is not possible to start two servers on different ports in the same time.
At the end, you can stop the server with the stop() method. A good place for that is an after-test block.
If you do not stop it, it will be automatically stopped after the test execution.
The expectations in this class are working similarly to other "ibello" expectations. They are also logged out and inserted into the result report. You can put them into complex expectations as well.
| Modifier and Type | Method and Description |
|---|---|
EmailExpectationBuilder |
assumeLastEmail()
Starts a soft expectation about the last email.
|
EmailExpectationBuilder |
expectLastEmail()
Starts a hard expectation about the last email.
|
FakeEmailServer |
reset()
Resets the email server and clears all emails from it.
|
FakeEmailServer |
start(int port)
Starts the email server on the given port.
|
FakeEmailServer |
stop()
Stops the email server.
|
FakeEmailServer start(int port)
port - the port where the server should be startedFakeEmailServer stop()
FakeEmailServer reset()
EmailExpectationBuilder expectLastEmail()
EmailExpectationBuilder assumeLastEmail()
Created by Kornél Simon, 2022