BDD para projetos .NET
Por que?
Facilidade
Facilidade Praticidade
Facilidade Praticidade Lingua nativa
Facilidade Praticidade Lingua nativa (ou quase isso)
Testes end-to-end
Testes end-to-end Como assim?
Testes end-to-end Interface Controller Repositorio BD
Testes end-to-end Interface Controller Repositorio BD User (browser)
Testes end-to-end Interface Controller Repositorio BD User (browser) Testa todas as camadas
Ferramentas
Ferramentas?
Ferramentas Selenium
Ferramentas Selenium (browser)
Ferramentas Selenium (browser) SpecFlow
Ferramentas Selenium (browser) SpecFlow (solução BDD)
Ferramentas Selenium (browser) SpecFlow (solução BDD) NUnit
Ferramentas Selenium (browser) SpecFlow (solução BDD) NUnit (framework de testes - asserções)
Sintaxe
Sintaxe Feature file:
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
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:
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:
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:
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:
Sintaxe
Sintaxe Resultado:
Sintaxe Resultado: Sintaxe
Sintaxe Vamos incrementar esse teste!
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:
Sintaxe Resultado: Sintaxe xtrumanx P@55w0Rd
O que testar?
O que testar? O que for importante
O que testar? O que for importante E 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 escrita 2. Difícil manutenção
Testes de aceitação tendem: 1. Difícil escrita 2. Difícil manutenção 3. Execução lenta
Testes de aceitação tendem: 1. Difícil escrita 2. Difícil manutenção 3. Execução lenta
Testes de aceitação tendem: 1. Difícil escrita 2. Difícil manutenção 3. Execução lenta
Testes de aceitação tendem: 1. Difícil escrita 2. Difícil manutenção 3. Execução lenta
Testes de aceitação tendem: 1. Difícil escrita 2. Difícil manutenção 3. Execução lenta 4. Feedback demorado
Testes de aceitação tendem: 1. Difícil escrita 2. Difícil manutenção 3. 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ão http://www.infoq.com/br/presentations/o-que-nao-testar

BDD in .NET projects