0

I am quite new to BDD, I am trying to use BDD in order to develop a simple signup module for a website.

I have the following scenario:

Scenario: An anonymous visitor successfully signs up with the website  
Given the following email address: john.smith@gmail.com and a chosen member status of childminder and the following password: ------ 
When the anonymous visitor signs up  
Then a confirmation email with activation information is sent to the anonymous visitor

I am quite at a loss automating the Then step ("Then a confirmation email with activation information is sent to the anonymous visitor")

Here is what I have undertaken (with JBehave):

@Given("the following email address: $email and a chosen member status of $status and the following password: $password")
public void anonymousVisitorEntersDetails(String email, String status, String password) {
    pages.home().open();
    pages.home().enterDetails(email, status, password);
}

@When("the anonymous visitor signs up")
public void anonymousVisitorDoesRegister(String login, String password) {
    pages.home().doRegister();
}

@Then("a confirmation email with activation information is sent to the anonymous visitor")
public void activationInformationIsSent() {
    //TODO ??
}

The issue I have is not so much a tool issue as a design issue. I would be grateful if some experienced BDD practitionner would help me sort this out...

balteo
  • 23,602
  • 63
  • 219
  • 412

1 Answers1

1

Let's start with your Given. This sets up the context. If I understand your scenario, relevant things that might be of interest are: - not logged in - on the home (or registration) page Do not mention user details here.

Next, your When step specifies what user details the anonymous user registers with.

Finally, the Then step needs to check that a confirmation email is sent. Although it is tempting to send an email & check that it arrives, this would IMO be a mistake. Email is not guaranteed to arrive and is slow in any case. Keep your test suite fast and robust.

Instead use the wording of your When statement, or a tag on the scenario, to indicate that your app should be constructed with a mock email component. In your Then step you can interrogate the mock to verify that it has been called as expected.

Somewhere in your tests you will still need an integration and/or acceptance test to validate that the 'real' email component has been deployed correctly. This might be a manual test, or it might be a slow & temperamental automated test that logs into a mail client and polls until an email with the expected content arrives.

Seb Rose
  • 3,628
  • 18
  • 29