O documento discute testes de aceitação para aplicações .NET usando Behavior Driven Development (BDD). Ele explica que BDD permite testes de ponta a ponta de forma fácil usando ferramentas como Selenium, SpecFlow e NUnit. A sintaxe BDD é demonstrada através de um exemplo de teste de login, mostrando como mapear cenários de teste para código. O documento também discute quais funcionalidades vale a pena testar e a importância de feedback rápido através de testes automatizados.
22. Sintaxe
Feature file:
Feature: Login
In order to access my account
As a user of the website
I want to log into the website
Scenario: Logging in with valid credentials
Given I am at the login page
When I fill in the following form
| field | value |
| Username | xtrumanx |
| Password | P@55w0Rd |
And I click the login button
Then I should be at the home page
23. Sintaxe
Feature file:
Feature: Login
In order to access my account
As a user of the website
I want to log into the website
Scenario: Logging in with valid credentials
Given I am at the login page
When I fill in the following form
| field | value |
| Username | xtrumanx |
| Password | P@55w0Rd |
And I click the login button
Then I should be at the home page
Feature definition:
24. Sintaxe
Feature file:
Feature: Login
In order to access my account
As a user of the website
I want to log into the website
Scenario: Logging in with valid credentials
Given I am at the login page
When I fill in the following form
| field | value |
| Username | xtrumanx |
| Password | P@55w0Rd |
And I click the login button
Then I should be at the home page
[Binding]
class LoginStepDefinitions
{
[Given("I am at the login page")]
public void GivenIAmAtTheLoginPage()
{
// TODO
}
}
Feature definition:
25. Sintaxe
Feature file:
Feature: Login
In order to access my account
As a user of the website
I want to log into the website
Scenario: Logging in with valid credentials
Given I am at the login page
When I fill in the following form
| field | value |
| Username | xtrumanx |
| Password | P@55w0Rd |
And I click the login button
Then I should be at the home page
[Binding]
class LoginStepDefinitions
{
[Given("I am at the login page")]
public void GivenIAmAtTheLoginPage()
{
// TODO
}
}
Feature definition:
26. Sintaxe
Feature file:
Feature: Login
In order to access my account
As a user of the website
I want to log into the website
Scenario: Logging in with valid credentials
Given I am at the login page
When I fill in the following form
| field | value |
| Username | xtrumanx |
| Password | P@55w0Rd |
And I click the login button
Then I should be at the home page
[Binding]
class LoginStepDefinitions
{
[Given("I am at the login page")]
public void GivenIAmAtTheLoginPage()
{
driver.Navigate.GoToUrl("www.gmail.com")
}
}
Feature definition:
31. Sintaxe
Feature file:
Feature: Login
In order to access my account
As a user of the website
I want to log into the website
Scenario: Logging in with valid credentials
Given I am at the login page
When I fill in the following form
| field | value |
| Username | xtrumanx |
| Password | P@55w0Rd |
And I click the login button
Then I should be at the home page
[Binding]
class LoginStepDefinitions
{
[When("I fill in the following form")]
public void
WhenIFillInTheFollowingForm(TechTalk.SpecFlow.Table table)
{
foreach(var row in table.Rows)
{
var textField =
driver.FindElement(By.Id(row["field"]));
if(!textField.Exists)
Assert.Fail("Expected to find a text field with the
name of '{0}'.", row["field"]);
textField.TypeText(row["value"]);
}
}
}
Feature definition: