Videos
Check out our tutorial video series.
Use disposable email accounts in espresso to test firebase authentication
If you have an android app it probably has a sign-up function. Many use Firebase or similar services to provide email and password based login with a confirmation link. In order to test this we can use Espresso with free MailSlurp temporary inboxes to generate unique email accounts for each test and use them to receive confirmation links, open them in a webview, and verify real accounts and user sign-up. Let's see how it works.
For this example we will use a test application hosted on GitHub that uses Firebase Auth to allow user sign-up. We will use the MailSlurp Java client to create email accounts on the fly then wait for a confirmation link.
The Espresso test flow looks like this:
In our example we will use Kotlin and Espresso with JUnit runner and the Android studio emulator to load the app and test user sign up of a Firebase authentication UI form. The app looks like this:
And our basic test file is this:
In your add the
client so we can control inboxes:
MailSlurp is free you just need to get a free API KEY and set it in the ApiClient config. In our tests import the client:
Then read your API Key from ENV or test arguments and set it on the client:
Set in the client like this:
Now we have the test and client setup we can test user authentication.
In order to test a firebase passwordless style auth flow we need a temporary mailbox that can receive an email address. Use the MailSlurp inbox controller to create one:
Now we can use the inbox we created to sign-up for an account:
The test looks like this:
After submitting the form Firebase will send an email to our disposable account.
Now we can wait for the email to arrive using the MailSlurp waitController and the fetch the links from the email using MailSlurp helper methods:
Next we want to click the verification link and open it in a browser:
Once the link opens we see a screen confirming our account:
Now that we have received the confirmation email and opened the link we can go back and assert our user is verified.
In our emulator this verified user account screen looks like this:
Wow - we just tested user sign-up and OTP links using real email accounts in Android end-to-end tests. Let's go over how we did that. First we used the MailSlurp Java client to create a throwaway mailbox for our test run. We then filled a sign up form backed by firebase and submitted our account. Next we used the methods in MailSlurp to hold test open until the expected confirmation email arrived. We extracted the link and opened it in Chrome. Then we reloaded our app and asserted the user verification.
You can use this technique too! MailSlurp is free for personal use so take a look today!
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.