JMeter is a powerful load testing framework from Apache that lets you run large scale stress tests against networks and APIs. Sometimes these systems rely on email messaging, for instance user sign-up, bulk marketing, email blasts, and notification systems. When email is required we can use disposable test email accounts from MailSlurp to send and receive email during JMeter tests.

A test scenario

Say we have a sign-up process in our application that accepts a user email address and then sends a confirmation code. What happens when our system is under heavy load, say during a live event or promotion? Well to test this we can use JMeter. We define steps using either a GUI, XML, or Java. These steps should do the following:

  1. Create a disposable email account on MailSlurp API
  2. Call the sign-up endpoint and submit the email address
  3. Wait for a confirmation code to arrive confirming functionality
  4. Repeat many times in parallel for load test

Setup

If you don't have JMeter already download it and place in your project root. Unzip the files and execute the GUI using:

This should show a user interface like so:

Controlling inboxes

To create email accounts during JMeter load tests use the free MailSlurp API. The key endpoints are:

RequestDescription
POST https://api.mailslurp.com/inboxesCreates a new disposable inbox and returns its id + emailAddress.
GET https://api.mailslurp.com/waitForLatestEmail?inboxId={INBOX_ID}&timeout=60000&unreadOnly=truePolls MailSlurp until the latest unread email arrives in that inbox.

Note: for each request we must append a MailSlurp API KEY as an header:

Creating the email load test

Let's go over the steps now needed to write the load test for our application sign up process.

1) Create email accounts in JMeter

To generate a new dummy mailbox make a request to with your API KEY set to the header. This returns an ID and emailAddress we can store for the next steps:

read email jmeter

Make sure we set the headers to pass a valid MailSlurp API KEY (Get a free key here).

jmeter-inbox-post-headers.png

Next we need to store the returned JSON result so we can sign up with the email address and then read the emails:

jmeter-create-email-store.png

2) Sign up using email

Now that we have an email in our load test, use it to sign up and stress test our application. Here we will test a dummy app:

jmeter-test-signup.png

If our system is working correctly it will send an email to that email address that we can wait for using MailSlurp.

3) Wait for and read email in JMeter

Lastly, we can now use the inbox ID stored earlier to receive the sent email and verify our system is operational during load tests. For this we call and pass a milliseconds and parameter. This will hold the connection open until our expected email arrives in the inbox. This makes waiting for emails easier without any additional retry logic.

jmeter-wait-for-email.png

Then test the email is present:

jmeter-wait-for-assert.png

Full JMX test example

Here is a full example you can save and load into JMeter:

You can run this test in the command line like this:

Running JMeter with mvn

Another way to write JMeter tests is with JUnit and maven. Here we can use the MailSlurp Java Library to create an inbox and receive the confirmation email after user sign up.

Get started

See the full examples on Github and go to MailSlurp to create a free account and start testing.