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
330
Introduction to automated tests (Goiania)
sobrinho
0
170
Otimização de Aplicações RoR
sobrinho
1
300
Introdução ao React (Simplificado)
sobrinho
0
160
Algoritmos de pesquisa
sobrinho
0
700
Introdução ao Docker
sobrinho
1
130
Introdução ao React
sobrinho
0
360
Other Decks in Programming
See All in Programming
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
130
Family mrubyの進捗
kishima
1
100
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
160
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
What We Talk About When We Talk About XP
m_seki
2
390
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
3
550
アクセシビリティから考える情報設計
high_g_engineer
0
300
自分的「カンファレンスの楽しみ方」
syumai
0
190
デプロイ直後のレイテンシスパイクを調べたら、 Railsの仕様にたどり着いた
nhsykym
0
110
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.9k
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
0
390
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
140
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Become a Pro
speakerdeck
PRO
31
6.2k
How to Think Like a Performance Engineer
csswizardry
28
2.8k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
490
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
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