Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
TDD com Javascript
Search
Breno Ferreira
May 27, 2013
Technology
540
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TDD com Javascript
Palestra sobre TDD com Javascript na trilha Web University do TDC2013 Floripa
Breno Ferreira
May 27, 2013
More Decks by Breno Ferreira
See All by Breno Ferreira
TDC Globo Sistemas Distribuídos
brenoferreira
1
110
Trabalho Remoto TDC Globo 2020
brenoferreira
1
130
Immutable Da
brenoferreira
0
100
Remote Work
brenoferreira
0
110
Fun with Types
brenoferreira
0
260
Monads na prática - QConSP 2014
brenoferreira
0
140
RxJava
brenoferreira
1
430
.NET Além do Mundo Microsoft
brenoferreira
0
120
TDC2013 - Programação assíncrona com Javascript
brenoferreira
1
600
Other Decks in Technology
See All in Technology
Code for Security プロジェクト紹介 2026年10月
yu23ki14
0
120
JAWS-UGグッズ職人仕事の流儀
kentapapa
0
130
こんにちは!SORACOM です & IoT とは【SORACOM UG 東北 in 八戸】
soracom
PRO
0
160
freeeにおける AI を用いた ブラウザ動作確認の自動化の取り組み
freee
PRO
0
110
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
170
データエンジニアの次の戦場は "プロセスエンジニアリング"
sansantech
PRO
1
150
国際カードブランドルール変更に伴うクレジットカード決済取引仕様変更について
k1style
0
130
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
150
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
220
SAENM ~Jupyterで残すPoCの試行錯誤、未来の自分と仲間を助ける記録!~
terapyon
0
170
Persisting Massive Data with Rails ~Designing for 60 billion rows, and fighting the bottlenecks~ Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
0
770
DevelopersIO2026 -バックアップは“消されないこと”が9割-
yoshida0129
0
240
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
How GitHub (no longer) Works
holman
316
150k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
760
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
530
Marketing to machines
jonoalderson
1
5.9k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
360
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
570
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
400
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
450
Building the Perfect Custom Keyboard
takai
2
910
Ruling the World: When Life Gets Gamed
codingconduct
0
410
The Cult of Friendly URLs
andyhume
79
7k
Transcript
Test-Driven Development Breno Ferreira @breno_ferreira http://github.com/brenoferreira
Você escreve testes?
Big Design Up-Front (BDUF)
Alto acoplamento
Comentários
Documentação
Código que precisa de explicação
Isso gera Bugs!
Isso gera #MEDO
Falta de motivação
Tem como ser produtivo assim?
Quem disse que construir software é fácil?
Por que testar?
Por que testar? Confiabilidade
Por que não testar?
Eu sou Jedi! Eu sou Sênior
Não temos tempo!
Acredite! Você NÃO é tão bom assim!
Mito Escrever testes demora muito, eu poderia ter implementado direto
Verdade Não escrever testes dá uma falta sensação de velocidade
None
None
Testar é necessário Não escrever testes é como um cirurgião
que não lava as mãos antes de uma operação | Robert “Uncle Bob” Martin
Testar é necessário Não escrever testes é anti-ético | Alguém
no twitter
Mas afina, o que são testes? • Código que executa
outro código • Verifica a exatidão de pressupostos • Caso esses pressupostos estejam corretos, o teste passa, senão, falha
Vantagens • Prover feedback • Tendem a melhorar o design
da aplicação • Contribui para manutenção • Documentação executável do seu código
Desvantagens
#Fatos • Se está dificil de testar, voce possivelmente está
fazendo algo errado • Testes ruins são piores que nenhum teste • Saber o que testar, no começo, é dificil
Tipos de teste • Unidade • Integração • Aceitação •
Carga
TDD Red Green Refactor
Show me the code!
Jasmine.JS http://pivotal.github.io/jasmine/
describe(‘Todos’, function(){ it(‘TodosView deve iniciar com lista vazia’, function(){ var
view = new TodosView(); expect(view.todos.length).toBe(0); }); });
it('cria todo', function(){ var view = new TodosView(); view.criarTodo('nova todo');
expect(view.todos.length).toBe(1); });
it('cria todo com nome passado por param', function(){ var view
= new TodosView(); var nomeTodo = 'nova todo'; view.criarTodo(nomeTodo); expect(view.todos[0].nome).toBe(nomeTodo); });
Jasmine-jQuery it('renderiza lista de todos', function(){ var listaTodos = ['tarefa1',
'tarefa2', 'tarefa3']; var view = new TodosView(tarefas); expect($('li:first')).toHaveText('tarefa1') });
Mocks & Stubs
it('salva todos', function(){ var collection = new TodosCollection( ['tarefa1', 'tarefa2',
'tarefa3']; ); spyOn(collection, 'save'); var view = new TodosView(collection); view.salvar(); expect($('#resultado')).toHaveText('Todos salvas'); });
it('salva todos chama metodo save', function(){ var collection = new
TodosCollection( ['tarefa1', 'tarefa2', 'tarefa3']; ); spyOn(collection, 'save'); var view = new TodosView(collection); view.salvar(); expect(collection.save).toHaveBeenCalled(); });
Sinon.JS
it('carrega todos do servidor', function(){ var collection = new TodosCollection();
var view = new TodosView(collection); view.listar(); server.requests[0].respond( 200, { "Content-Type": "application/json" }, JSON.stringify(['tarefa1', 'tarefa2']); ); expect(view.todos[0].nome).toBe('tarefa1'); });
http://dnad.azurewebsites.net
Perguntas
Obrigado • @breno_ferreira •
[email protected]
• Aproveitem o evento •
Inscrevam-se no DNAD