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

Introduction to automated tests

Introduction to automated tests

Gabriel Sobrinho

June 10, 2017
Tweet

More Decks by Gabriel Sobrinho

Other Decks in Programming

Transcript

  1. Automated Tests • Ensure code quality • Avoid regressions •

    Reduce maintenance cost • Code and behavior documentation
  2. Test-Driven Development $ ruby calc.rb calc.rb:1:in `sum_all’: wrong number of

    arguments (given 1, expected 0) (ArgumentError) from calc.rb:4:in `<main>'
  3. Behavior-Driven Development BDD is a subset of TDD that enforces

    the story telling format to be clear about the expectations
  4. Behavior-Driven Development TDD focuses on each and every unit test

    for every function, doesn't matter what it does https://softwareengineering.stackexchange.com/a/224102
  5. Behavior-Driven Development Failures: 1) #sum_all sums the given numbers Failure/Error:

    expect(sum_all([1, 2, 3])).to eq 6 NoMethodError: undefined method `sum_all’ for #<RSpec::ExampleGroups::SumAll:0x007f8d5fa49270> # calc.rb:5:in `block (2 levels) in <main>' Finished in 0.00052 seconds (files took 0.09426 seconds to load) 1 example, 1 failure
  6. Behavior-Driven Development $ rspec calc.rb . Finished in 0.00207 seconds

    (files took 0.09914 seconds to load) 1 example, 0 failures
  7. Behavior-Driven Development $ rspec calc.rb . Finished in 0.00085 seconds

    (files took 0.09119 seconds to load) 1 example, 0 failures
  8. Unit Testing - BDD describe '#sum_all' do it 'sums the

    given numbers' do expect(sum_all([1, 2, 3])).to eq 6 end end
  9. Integrated Testing describe ZipCode do it 'returns the street information'

    do # Hits an API call zip_code = ZipCode.find('21510-140') expect(zip_code.number).to eq '21510-140' expect(zip_code.street).to eq 'Some Avenue' end end
  10. Acceptance Testing Tests if the software really works as the

    final customer or stakeholder expects it to work
  11. Acceptance Testing Feature: Buy a product Scenario: Using a discount

    code Given I have a discount code When I buy a product using that code Then the total must include that discount
  12. Ratio Artefact about how many line of tests there are

    for how many lines of code you have
  13. Coverage Artefact about if the line of code was run

    or wasn’t run during the test suite
  14. FAQ

  15. How to test? By the collacteral effects that the application

    causes, not by the implementation itself
  16. Write the tests before or after? Doesn’t matter after all,

    use the best for your project and team
  17. • 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