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
510
1
Share
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
98
Trabalho Remoto TDC Globo 2020
brenoferreira
1
120
Immutable Da
brenoferreira
0
96
Remote Work
brenoferreira
0
98
Fun with Types
brenoferreira
0
230
Monads na prática - QConSP 2014
brenoferreira
0
130
RxJava
brenoferreira
1
410
.NET Além do Mundo Microsoft
brenoferreira
0
93
TDC2013 - Programação assíncrona com Javascript
brenoferreira
1
570
Other Decks in Technology
See All in Technology
Eight Engineering Unit 紹介資料
sansan33
PRO
3
7.3k
Good Enough Types: Heuristic Type Inference for Ruby
riseshia
1
210
マルチエージェント × ハーネスエンジニアリング × GitLab Duo Agent Platformで実現する「AIエージェントに仕事をさせる時代へ。」 / 20260421 GitLab Duo Agent Platform
n11sh1
0
160
20260428_Product Management Summit_Loglass_JoeHirose
loglassjoe
0
260
国内外の生成AIセキュリティの最新動向 & AIガードレール製品「chakoshi」のご紹介 / Latest Trends in Generative AI Security (Domestic & International) & Introduction to AI Guardrail Product "chakoshi"
nttcom
2
340
EarthCopilotに学ぶマルチエージェントオーケストレーション
nakasho
0
290
Introduction to Bill One Development Engineer
sansan33
PRO
0
410
No Types Needed, Just Callable Method Check
dak2
1
1.2k
Pure Intonation on Browser: Building a Sequencer with Ruby
nagachika
0
110
レビューしきれない?それは「全て人力でのレビュー」だからではないでしょうか
amixedcolor
0
320
みんなで作るAWS Tips 100連発 (FinOps編)
schwrzktz
1
300
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3.1k
Featured
See All Featured
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
200
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.3k
Designing for humans not robots
tammielis
254
26k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
180
Abbi's Birthday
coloredviolet
2
7.1k
The Cost Of JavaScript in 2023
addyosmani
55
9.8k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
SEO for Brand Visibility & Recognition
aleyda
0
4.5k
What does AI have to do with Human Rights?
axbom
PRO
1
2.1k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
130
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
200
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