Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
TDD com Javascript
Search
Breno Ferreira
May 27, 2013
Technology
540
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
100
Remote Work
brenoferreira
0
110
Fun with Types
brenoferreira
0
260
Monads na prática - QConSP 2014
brenoferreira
0
140
RxJava
brenoferreira
1
420
.NET Além do Mundo Microsoft
brenoferreira
0
110
TDC2013 - Programação assíncrona com Javascript
brenoferreira
1
590
Other Decks in Technology
See All in Technology
ファミコンでPHPを動かす / PHP on the Famicom side b
tomzoh
0
110
More Freedom on the Same Shared GPU Cluster: A Small Team’s Experience with vCluster
nttcom
0
110
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
440
メルカリにおけるAI時代の高速プロトタイピング基盤「Arca」
ryotarai
18
14k
Execution in the Kingdom of Agents: Reflections on Abstraction and Complexity
bcantrill
0
770
『GOエコノミー 』(相乗りサービス) におけるスペック駆動開発
mot_techtalk
1
250
OSC2026on_the-world-is-waiting-for-your-voice.pdf
naruoga
0
320
3人で1000GPU超を統合運用する?マルチクラウド&オンプレを跨ぐ、構築と運用のリアル!
kazukun0716
2
830
AI Made Us Faster at Solving the Wrong Problems
marceloancelmo
0
150
[2026 Oracle Technical Deep Dive] AI時代のアプリケーションを支えるCloud NativeとJava EEモダナイゼーション (2026年9月17日開催)
oracle4engineer
PRO
0
100
Swap and Memory Reclaim - Squeezing Out More RAM
ennael
PRO
1
1.6k
カンファレンスに参加した後の浮遊感とセルフケア
pauli
0
300
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Bash Introduction
62gerente
615
220k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
590
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
How to build a perfect <img>
jonoalderson
1
6.1k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
260
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Odyssey Design
rkendrick25
PRO
2
850
The Invisible Side of Design
smashingmag
301
52k
BBQ
matthewcrist
89
10k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
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