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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
95
Trabalho Remoto TDC Globo 2020
brenoferreira
1
110
Immutable Da
brenoferreira
0
94
Remote Work
brenoferreira
0
95
Fun with Types
brenoferreira
0
230
Monads na prática - QConSP 2014
brenoferreira
0
130
RxJava
brenoferreira
1
400
.NET Além do Mundo Microsoft
brenoferreira
0
89
TDC2013 - Programação assíncrona com Javascript
brenoferreira
1
560
Other Decks in Technology
See All in Technology
Bill One 開発エンジニア 紹介資料
sansan33
PRO
5
18k
SSoT(Single Source of Truth)で「壊して再生」する設計
kawauso
2
410
20260326_AIDD事例紹介_ULSC.pdf
findy_eventslides
0
320
Embeddings : Symfony AI en pratique
lyrixx
0
440
OpenClaw初心者向けセミナー / OpenClaw Beginner Seminar
cmhiranofumio
0
120
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
4
1.3k
AWS DevOps Agent or Kiro の使いどころを考える_20260402
masakiokuda
0
140
Even G2 クイックスタートガイド(日本語版)
vrshinobi1
0
180
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
10
77k
CloudFrontのHost Header転送設定でパケットの中身はどう変わるのか?
nagisa53
1
230
制約を設計する - 非決定性との境界線 / Designing constraints
soudai
PRO
3
270
私がよく使うMCPサーバー3選と社内で安全に活用する方法
kintotechdev
0
150
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
The Cult of Friendly URLs
andyhume
79
6.8k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Thoughts on Productivity
jonyablonski
76
5.1k
The agentic SEO stack - context over prompts
schlessera
0
720
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
110
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
170
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
420
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