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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Breno Ferreira
May 27, 2013
Technology
1
510
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
91
Trabalho Remoto TDC Globo 2020
brenoferreira
1
110
Immutable Da
brenoferreira
0
90
Remote Work
brenoferreira
0
90
Fun with Types
brenoferreira
0
230
Monads na prática - QConSP 2014
brenoferreira
0
130
RxJava
brenoferreira
1
390
.NET Além do Mundo Microsoft
brenoferreira
0
84
TDC2013 - Programação assíncrona com Javascript
brenoferreira
1
560
Other Decks in Technology
See All in Technology
Oracle Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
3
1.7k
タスク管理も1on1も、もう「管理」じゃない ― KiroとBedrock AgentCoreで変わった"判断の仕事"
yusukeshimizu
5
2.5k
僕、S3 シンプルって名前だけど全然シンプルじゃありません よろしくお願いします
yama3133
1
190
トップマネジメントとコンピテンシーから考えるエンジニアリングマネジメント
zigorou
4
830
開発組織の課題解決を加速するための権限委譲 -する側、される側としての向き合い方-
daitasu
5
570
「ストレッチゾーンに挑戦し続ける」ことって難しくないですか? メンバーの持続的成長を支えるEMの環境設計
sansantech
PRO
3
620
決済サービスを支えるElastic Cloud - Elastic Cloudの導入と推進、決済サービスのObservability
suzukij
2
590
複数クラスタ運用と検索の高度化:ビズリーチにおけるElastic活用事例 / ElasticON Tokyo2026
visional_engineering_and_design
0
130
元エンジニアPdM、IDEが恋しすぎてCursorに全業務を集約したら、スライド作成まで爆速になった話
doiko123
1
580
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
8
7.2k
越境する組織づくり ─ 多様性を前提にしたチームビルディングとリードの実践知
kido_engineer
2
180
JAWS DAYS 2026 楽しく学ぼう!ストレージ 入門
yoshiki0705
2
140
Featured
See All Featured
How to Talk to Developers About Accessibility
jct
2
150
What's in a price? How to price your products and services
michaelherold
247
13k
Visualization
eitanlees
150
17k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
130
Become a Pro
speakerdeck
PRO
31
5.8k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
270
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
170
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
150
Building Applications with DynamoDB
mza
96
7k
Documentation Writing (for coders)
carmenintech
77
5.3k
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