Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to automated tests
Search
Gabriel Sobrinho
June 10, 2017
Programming
250
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to automated tests
Gabriel Sobrinho
June 10, 2017
More Decks by Gabriel Sobrinho
See All by Gabriel Sobrinho
Arquiteturas Multi-Tenant RubyConf 2022
sobrinho
0
240
Introduction to Go
sobrinho
1
130
Casos de otimização em aplicações Ruby on Rails
sobrinho
0
320
Introduction to automated tests (Goiania)
sobrinho
0
170
Otimização de Aplicações RoR
sobrinho
1
290
Introdução ao React (Simplificado)
sobrinho
0
160
Algoritmos de pesquisa
sobrinho
0
690
Introdução ao Docker
sobrinho
1
130
Introdução ao React
sobrinho
0
360
Other Decks in Programming
See All in Programming
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
160
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
Contextとはなにか
chiroruxx
1
390
どこまでゆるくて許されるのか
tk3fftk
0
350
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.9k
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
290
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
20260623_Loop Engineeringで自分の分身の問い合わせBotを作る
ryugen04
0
130
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
1
100
Vite+ Unified Toolchain for the Web
naokihaba
0
670
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
1k
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
100
Featured
See All Featured
Music & Morning Musume
bryan
47
7.3k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
610
A Soul's Torment
seathinner
6
3k
Producing Creativity
orderedlist
PRO
348
40k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
330
Claude Code のすすめ
schroneko
67
230k
Being A Developer After 40
akosma
91
590k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
RailsConf 2023
tenderlove
30
1.5k
Visualization
eitanlees
152
17k
It's Worth the Effort
3n
188
29k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Transcript
Introduction to Automated Tests Gabriel Sobrinho
GABRIEL SOBRINHO gabrielsobrinho.com github.com/sobrinho speakerdeck.com/sobrinho
hite.com.br
Concepts
TDD BDD Unit Tests Integrated Tests Acceptance Tests Coverage Test
Ratio Human Tester Test Automation
None
Human Tester
Human Tester Normally done by the QA department, a person
who exercises the software
None
None
Automated Tests
Automated Tests In software testing, a software that compares actual
outcomes with predicted outcomes
Automated Tests • Ensure code quality • Avoid regressions •
Reduce maintenance cost • Code and behavior documentation
Automated Tests def sum(a, b) a + b end
Automated Tests if sum(1, 2) == 3 puts 'okay' else
puts 'error' end
Automated Tests $ ruby calc.rb okay
Automated Tests if sum(0.1, 0.2) == 0.3 puts 'okay' else
puts 'error' end
Automated Tests $ ruby calc.rb error
None
Test-Driven Development
Test-Driven Development Write tests before the code itself to get
fast feedback
Test-Driven Development Red-Green-Refactor Cycle
Test-Driven Development Recommended by XP community
https://bitbucket.org/spooning/
Test-Driven Development if sum_all([1, 2, 3]) == 6 puts 'okay'
else puts 'error' end
Test-Driven Development $ ruby calc.rb calc.rb:1:in `<main>': undefined method `sum_all’
for main:Object (NoMethodError)
Test-Driven Development def sum_all end
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>'
Test-Driven Development def sum_all(numbers) end
Test-Driven Development $ ruby calc.rb error
Test-Driven Development def sum_all(numbers) total = 0 numbers.each do |number|
total += number end total end
Test-Driven Development $ ruby calc.rb okay
Test-Driven Development def sum_all(numbers) total = 0 numbers.each do |number|
total += number end total end
Test-Driven Development def sum_all(numbers) numbers.reduce(:+) end
Test-Driven Development $ ruby calc.rb okay
Test-Driven Development Red-Green-Refactor Cycle
None
Behavior-Driven Development
Behavior-Driven Development BDD is a subset of TDD that enforces
the story telling format to be clear about the expectations
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
Behavior-Driven Development BDD focuses on software that matters https://softwareengineering.stackexchange.com/a/224102
Behavior-Driven Development class TestCalculator < Test::Unit::TestCase def test_sum_all assert sum_all([1,
2, 3]) == 6 end end
Behavior-Driven Development describe '#sum_all' do it 'sums the given numbers'
do expect(sum_all([1, 2, 3])).to eq 6 end end
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
Behavior-Driven Development def sum_all(numbers) total = 0 numbers.each do |number|
total += number end total end
Behavior-Driven Development $ rspec calc.rb . Finished in 0.00207 seconds
(files took 0.09914 seconds to load) 1 example, 0 failures
Behavior-Driven Development def sum_all(numbers) numbers.reduce(:+) end
Behavior-Driven Development $ rspec calc.rb . Finished in 0.00085 seconds
(files took 0.09119 seconds to load) 1 example, 0 failures
None
Unit Testing
Unit Testing Tests about the smallest piece of the software
Unit Testing - TDD class TestCalculator < Test::Unit::TestCase def test_sum_all
assert sum_all([1, 2, 3]) == 6 end end
Unit Testing - BDD describe '#sum_all' do it 'sums the
given numbers' do expect(sum_all([1, 2, 3])).to eq 6 end end
None
Integrated Testing
Integrated Testing Tests the connected pieces of the software like
databases or APIs
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
None
Acceptance Testing
Acceptance Testing Tests if the software really works as the
final customer or stakeholder expects it to work
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
None
Artefacts
Ratio Artefact about how many line of tests there are
for how many lines of code you have
Coverage Artefact about if the line of code was run
or wasn’t run during the test suite
None
FAQ
What to test? Everything, from isolated code, to integrated pieces
and to the entire system connected
How to test? By the collacteral effects that the application
causes, not by the implementation itself
Write the tests before or after? Doesn’t matter after all,
use the best for your project and team
Which methodology? Doesn’t matter after all, use the best for
your project and team
Which test runner? Doesn’t matter after all, use the best
for your project and team
None
Questions?
Thanks!
• 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