Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to automated tests (Goiania)

Introduction to automated tests (Goiania)

Gabriel Sobrinho

March 10, 2018
Tweet

More Decks by Gabriel Sobrinho

Other Decks in Programming

Transcript

  1. Bug

  2. A software bug is an error in a program that

    causes it to produce an incorrect result or misbehave unintentionally
  3. $ ruby tdd.rb tdd.rb:1:in `sum_all': wrong number of arguments (given

    1, expected 0) (ArgumentError) from tdd.rb:4:in `<main>'
  4. BDD is a subset of TDD that enforces the story

    telling format to be clear about the expectations
  5. TDD focuses on each and every unit test for every

    function, doesn't matter what it does https://softwareengineering.stackexchange.com/a/224102
  6. Feature: Calculator As Einstein I want a calculator So I

    can perform basic operations Scenario: Subtraction Given I have two numbers When I subtract them Then I want the difference
  7. Given 'I have two numbers' do @a = 6 @b

    = 3 end When 'I subtract them' do @result = subtract(@a, @b) end Then 'I want the difference' do assert @result == 3 end
  8. Feature: Calculator As Einstein I want a calculator So I

    can perform basic operations Scenario: Subtraction Given I have two numbers When I subtract them undefined method `subtract' for #<Object: 0x00007fd094cb5018> (NoMethodError) calc.rb:7:in `/^I\ subtract\ them$/' calc.feature:8:in `When I subtract them' Then I want the difference Failing Scenarios: cucumber calc.feature:6 # Scenario: Subtraction 1 scenario (1 failed) 3 steps (1 failed, 1 skipped, 1 passed) 0m0.021s
  9. Feature: Calculator As Einstein I want a calculator So I

    can perform basic operations Scenario: Subtraction Given I have two numbers When I subtract them wrong number of arguments (given 2, expected 0) (ArgumentError) calc.rb:1:in `subtract' calc.rb:10:in `/^I\ subtract\ them$/' calc.feature:8:in `When I subtract them' Then I want the difference Failing Scenarios: cucumber calc.feature:6 # Scenario: Subtraction 1 scenario (1 failed) 3 steps (1 failed, 1 skipped, 1 passed) 0m0.021s
  10. Feature: Calculator As Einstein I want a calculator So I

    can perform basic operations Scenario: Subtraction Given I have two numbers When I subtract them SolidAssert::AssertionFailedError (SolidAssert::AssertionFailedError) calc.rb:14:in `/^I\ want\ the\ difference$/' calc.feature:9:in `Then I want the difference' Then I want the difference Failing Scenarios: cucumber calc.feature:6 # Scenario: Subtraction 1 scenario (1 failed) 3 steps (1 failed, 1 skipped, 1 passed) 0m0.021s
  11. Feature: Calculator As Einstein I want a calculator So I

    can perform basic operations Scenario: Subtraction Given I have two numbers When I subtract them Then I want the difference 1 scenario (1 passed) 3 steps (3 passed) 0m0.019s
  12. describe ZipCode do it 'returns the street information' do #

    Triggers a HTTP API call zip_code = ZipCode.find('12345') expect(zip_code.number).to eq '12345' expect(zip_code.street).to eq 'Some Avenue' end end
  13. You may open the browser and click on a button

    and expect something to happen
  14. feature 'Buy' do scenario 'Buy a product using credit card'

    do visit '/products/1' click_on 'Buy' expect(page).to have_content 'Order made' expect(credit_card).to have_charged 14.99 end end
  15. Code to Test Ratio How many lines of production code

    there are against lines of test code
  16. • http://www.devmedia.com.br/artigo-engenharia-de-software-3-a-importancia-dos-testes- automatizados/9532 • http://www.eduardopires.net.br/2012/06/ddd-tdd-bdd/ • http://tdd.caelum.com.br • https://cbabhusal.wordpress.com/2016/02/26/tdd-why-red-green-refactor-is-important-in-tdd/ •

    https://ciclosw.wordpress.com/2014/09/04/diferenca-entre-tdd-e-bdd/ • http://blog.locaweb.com.br/artigos/metodologias-ageis/diferenca-entre-bdd-tdd/ • https://www.infoq.com/news/2015/02/bdd-ddd • http://www.princiweb.com.br/blog/programacao/tdd/tdd-ddd-e-bdd-praticas-de- desenvolvimento.html • http://www.agileandart.com/2010/07/16/ddd-introducao-a-domain-driven-design/ References