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
1
500
TDD com Javascript
Palestra sobre TDD com Javascript na trilha Web University do TDC2013 Floripa
Breno Ferreira
May 27, 2013
Tweet
Share
More Decks by Breno Ferreira
See All by Breno Ferreira
TDC Globo Sistemas Distribuídos
brenoferreira
1
79
Trabalho Remoto TDC Globo 2020
brenoferreira
1
99
Immutable Da
brenoferreira
0
79
Remote Work
brenoferreira
0
83
Fun with Types
brenoferreira
0
220
Monads na prática - QConSP 2014
brenoferreira
0
120
RxJava
brenoferreira
1
380
.NET Além do Mundo Microsoft
brenoferreira
0
77
TDC2013 - Programação assíncrona com Javascript
brenoferreira
1
550
Other Decks in Technology
See All in Technology
Agent Skillsがハーネスの垣根を超える日
gotalab555
7
4.9k
Authlete で実装する MCP OAuth 認可サーバー #CIMD の実装を添えて
watahani
0
300
テストセンター受験、オンライン受験、どっちなんだい?
yama3133
0
200
Oracle Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
1
790
Strands Agents × インタリーブ思考 で変わるAIエージェント設計 / Strands Agents x Interleaved Thinking AI Agents
takanorig
6
2.4k
Bedrock AgentCore Evaluationsで学ぶLLM as a judge入門
shichijoyuhi
2
300
re:Invent2025 セッションレポ ~Spec-driven development with Kiro~
nrinetcom
PRO
2
160
ECS_EKS以外の選択肢_ROSA入門_.pdf
masakiokuda
1
120
普段使ってるClaude Skillsの紹介(by Notebooklm)
zerebom
8
2.6k
『君の名は』と聞く君の名は。 / Your name, you who asks for mine.
nttcom
1
130
AIBuildersDay_track_A_iidaxs
iidaxs
4
1.6k
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
10k
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
770
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.5k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
200
Color Theory Basics | Prateek | Gurzu
gurzu
0
160
Designing Powerful Visuals for Engaging Learning
tmiket
0
190
4 Signs Your Business is Dying
shpigford
187
22k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
65
35k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
130
We Have a Design System, Now What?
morganepeng
54
8k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.2k
Chasing Engaging Ingredients in Design
codingconduct
0
92
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