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
TDD com Javascript
Search
Breno Ferreira
May 27, 2013
Technology
530
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
98
Remote Work
brenoferreira
0
100
Fun with Types
brenoferreira
0
250
Monads na prática - QConSP 2014
brenoferreira
0
130
RxJava
brenoferreira
1
420
.NET Além do Mundo Microsoft
brenoferreira
0
100
TDC2013 - Programação assíncrona com Javascript
brenoferreira
1
580
Other Decks in Technology
See All in Technology
インシデント事例と パッケージの全量解析に学ぶ ソフトウェアサプライチェーンの守り方 / supply-chain-attack-defense
flatt_security
0
1.1k
AI研修(Day1)【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
860
プロダクト開発組織の現在地(Ver.2026/07) / product-organization
kaonavi
0
480
発表と総括 / Presentations and Summary
ks91
PRO
0
210
変更し続けられるシステムをどう保つか — AI時代のSSoTという設計原則
kawauso
1
1.2k
コンテナ・K8s研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
170
AI Agent を本番環境へ―― Microsoft Foundry × Azure Serverless で作る Enterprise-Ready な基盤
shibayan
PRO
1
450
Flutter研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
100
データと地図で読む 大井町の「かわるもの、かわらないもの」
yoshiyama_hana
0
300
PHPで作って学ぶリアルタイム音声対話AIとWebSocket入門 by ムナカタ
munakata
0
150
VPCセキュリティ対応の最新事情
nagisa53
1
330
AIエージェントがあれば技術書なんてすぐ書けるでしょ→無理でした
watany
4
440
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
340
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
390
The Mindset for Success: Future Career Progression
greggifford
PRO
0
430
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Site-Speed That Sticks
csswizardry
13
1.3k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
460
Bash Introduction
62gerente
615
220k
Crafting Experiences
bethany
1
230
Odyssey Design
rkendrick25
PRO
2
730
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