BDD para projetos .NET
Por que?
Facilidade
Facilidade
Praticidade
Facilidade
Praticidade
Lingua nativa
Facilidade
PraticidadeLingua nativa (ou
quase isso)
Testes end-to-end
Testes end-to-end
Como assim?
Testes end-to-end
Interface Controller RepositorioBD
Testes end-to-end
Interface Controller RepositorioBD
User (browser)
Testes end-to-end
Interface Controller RepositorioBD
User (browser)
Testa todas as camadas
Ferramentas
Ferramentas?
FerramentasSelenium
FerramentasSelenium (browser)
FerramentasSelenium (browser)
SpecFlow
FerramentasSelenium (browser)SpecFlow (solução
BDD)
FerramentasSelenium (browser)SpecFlow (solução
BDD)NUnit
FerramentasSelenium (browser)SpecFlow (solução
BDD)NUnit (framework de testes - asserções)
Sintaxe
SintaxeFeature
file:
SintaxeFeature
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
SintaxeFeature
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:
SintaxeFeature
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:
SintaxeFeature
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:
SintaxeFeature
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:
Sintaxe
SintaxeResultado:
SintaxeResultado:Sintaxe
SintaxeVamos incrementar esse teste!
SintaxeFeature
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:
SintaxeResultado:Sintaxe
xtrumanx
P@55w0Rd
O que testar?
O que testar?O que for
importante
O que testar?O que for
importanteE porque não tudo?
Testes de aceitação tendem:
Testes de aceitação tendem:
1. Difícil escrita
Testes de aceitação tendem:
1. Difícil escrita2. Difícil manutenção
Testes de aceitação tendem:
1. Difícil escrita2. Difícil manutenção
3. Execução lenta
Testes de aceitação tendem:
1. Difícil escrita2. Difícil manutenção3. Execução lenta
Testes de aceitação tendem:
1. Difícil escrita2. Difícil manutenção3. Execução lenta
Testes de aceitação tendem:
1. Difícil escrita2. Difícil manutenção3. Execução lenta
Testes de aceitação tendem:
1. Difícil escrita2. Difícil manutenção3. Execução lenta
4. Feedback demorado
Testes de aceitação tendem:
1. Difícil escrita2. Difícil manutenção3. Execução lenta
4. Feedback demorado
Cenário ideal:
Cenário ideal:
*quase* ideal
Cenário ideal:
ideal
Por que?Feedback rápido é
importante
Por que?Feedback rápido é
importante
Por que?Feedback rápido é
importante
Por que?Feedback rápido é
importante
Sugestão
Sugestãohttp://www.infoq.com/br/presentations/o-que-nao-testar