Videos
Check out our tutorial video series.
Testing .NET authentication and sign-up with MailSlurp and SpecFlow, using real email accounts - see how it's done in this tutorial!
Specflow is a great end-to-end behavior driven test framework for CSharp and .NET application. It is used by many developer to test common scenarios in DotNet applications using a BDD Cucumber like syntax. With MailSlurp you can generate test email accounts during tests to test features like user sign-up end-to-end using real email addresses. In this post we will show you how!
View full code examples on GitHub.
We can use a simple React App deployed to playground.mailslurp.com for this demonstration. It has a common authentication flow that allows users to sign up with an email and password. After signing up users receive a confirmation code via email. The code can then be submitted to the app to verify the user. The user can then login and see a picture of a happy dog.
The best way to get started with a Specflow project is to use VisualStudio to scaffold a project. Install the official Specflow plugin like so:
Then create a new project using the plugin:
Choose a runner when prompted: We recommend MSTest for this example.
Now add Selenium and MailSlurp to your file:
MailSlurp is free to use but you need to obtain an API Key. Create a free account to get your API Key.
Next wee need to fetch a webdriver for use with Selenium. We use internally so create a
like so:
Running will download a webdriver for Firefox to the local directory. Running
will run our tests and pass the driver path to our tests.
Once install we can create features. Features use a Specflow syntax similar to Cucumber BDD. We describe the actions a user may take and the results we expect. An example for our demonstration app might look like this:
Each step in the scenario maps to functions that we define next in our definition steps.
Each feature statement we write needs to be bound to a CSharp step definition. Here is how we do it:
Notice how each step binding uses an annotation to match a line in our feature file. Let's look at some of the important steps.
We can use MailSlurp's InboxControllerApi class to generate real test email accounts during each test. This means our user can have a real email account for each test. We can use the email address to sign up and receive a confirmation code.
We expect a confirmation code to be sent to our user email address like the following:
Use the WaitForControllerApi class to wait for the latest email in the inbox we created. Then we can use a regex pattern to match the email content for a verification code.
SpecFlow works with many test adapters such as NUnit and xUnit. We will use MSTest to run our tests. We can run tests with . We should see Selenium automate a browser and perform a user sign up.
Testing .NET user sign up flows using Specflow is easy with MailSlurp. You can create test email accounts for free and test user funciton end to end. Create a free account to get started or see the CSharp developer docs.
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.