Top Banner
Testing Sucks Leo Balter - BrazilJS 2012 JS
139

Testing sucks

May 17, 2015

Download

Technology

Leonardo Balter

Presentation given in BrazilJS 2012
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Testing sucks

Testing SucksLeo Balter - BrazilJS 2012 JS

Page 2: Testing sucks

Testar é chato!

Page 3: Testing sucks

Testes vs Testar!

Page 4: Testing sucks

Testes humanos• Repetitivos

• Estressantes

• Cansativos

Page 5: Testing sucks

Concentração polarizada

• Nos concentramos em um único ponto

• Não vemos os demais

• falsa sensação de segurança

Page 6: Testing sucks

Olhar Viciado

Page 7: Testing sucks

Testes de Trollagem

Page 8: Testing sucks

Pare de “ficar testando” seu código

Page 9: Testing sucks

JSHint/JSLint não testa código!

• Convenção de estilo

• Erros comuns

• “As Boas Partes”

Page 10: Testing sucks

Mito do Compilador

Page 11: Testing sucks

Pânico vs Benefícios

• Muito fácil criar testes para algo que ainda não existe

• Não tão simples quando a aplicação já existe e está “no ar”.

Page 12: Testing sucks

Aplicação não testada

Page 13: Testing sucks

A Síndrome do “o que está

funcionando não se deve mexer”.

Page 14: Testing sucks

Quebre a aplicação!• Criamos testes simples que passem

• Teste o que está em produção

• Cobertura de testes

• O que é crítico?

• Especificação

• O que falta testar?

• Testes de Trollagem

Page 15: Testing sucks

Acredite:Sua aplicação vai falhar!

Page 16: Testing sucks

Já viu essa síndrome?

• Não vai ao médico pra evitar descobrir um mal grave

• Pode haver um problema latente que vai falhar em um momento crítico

• Pode acabar em morte

Page 17: Testing sucks

Na aplicação

• Não testamos para não descobrir o que falha

• Há problemas latentes que vão falhar em momentos críticos (Por exemplo: um sistema de pagamento do seu e-commerce)

• Sua empresa morre (vai a falência)

Page 18: Testing sucks

Estabeleça o que é crítico

• Quão crítico é cada parte do seu sistema?

• Se não funcionar, quais as consequências?

Page 19: Testing sucks

Impacto

Ocorrência

Baixo

Baixo Alto

Alto

Risco de baixo nível

Risco de nível médio

Risco Crítico

http://bit.ly/11tTwNGerenciamento de Risco

Page 20: Testing sucks

Automatização

• --Retrabalho

• --Surpresas

• Mais tempo para o que é interessante

• Menos tempo para testar tudo novamente

Page 21: Testing sucks

Automatização

• --Retrabalho

• --Surpresas

• Mais tempo para o que é interessante

• Menos tempo para testar tudo novamente

Page 22: Testing sucks

Metodologias Ágeis

• Aplicar testes é uma rotina contida em Metodologias Ágeis

• Testes não dependem de metodologias ágeis

• Ex.: jQuery

Page 23: Testing sucks

Funciona

Faz o que deveria

Page 24: Testing sucks

Esse código funciona!

• Um código pode funcionar perfeitamente

• Estar 100% testado

• e não cumprir 10% do seu papel

Page 25: Testing sucks

Fluxo

Page 26: Testing sucks

Especificação

Fluxo

Page 27: Testing sucks

Especificação

Plano de Testes

Fluxo

Page 28: Testing sucks

Especificação

Plano de Testes

TestesFluxo

Page 29: Testing sucks

Validação

Page 30: Testing sucks

Plano de Testes

Validação

Page 31: Testing sucks

Especificação

Plano de Testes

Validação

Page 32: Testing sucks

Especificação

Plano de Testes Testes

Validação

Page 33: Testing sucks

Especificação

Plano de Testes Testes

Aplicação

Validação

Page 34: Testing sucks

Testes não validam especificação!

Testes não criam especificação!

Page 35: Testing sucks

Testes vs Especificação

• Se os testes validassem especificação, não poderiamos prever correções de bugs e comportamentos de ambientes.

• Bugs não fazem parte de uma especificação.

Page 36: Testing sucks

Baby Steps (Testes Unitários)

Teste que Falha Código Refatorar

Page 37: Testing sucks

Sempre em Baby Steps

• Ótimo para pegar o ritmo

• função 1, 2, 3, pin

• Treino do Lutador

Page 38: Testing sucks

Coberturade

Código

Page 39: Testing sucks

function foo( bar ) { if ( bar ) { console.log( 'yes!' ); else { console.log( 'no!' ); }}

Page 40: Testing sucks

function foo( bar ) { if ( bar ) { console.log( 'yes!' ); else { console.log( 'no!' ); }}

Page 41: Testing sucks

function foo( bar ) { if ( bar ) { console.log( 'yes!' ); else { console.log( 'no!' ); }}

Page 42: Testing sucks

function foo( bar ) { if ( bar ) { console.log( 'yes!' ); else { console.log( 'no!' ); }}

Page 43: Testing sucks

function foo( bar ) { if ( bar ) { console.log( 'yes!' ); else { console.log( 'no!' ); }}

Page 44: Testing sucks

function foo( bar ) { if ( bar ) { console.log( 'yes!' ); else { console.log( 'no!' ); }}

Page 45: Testing sucks

Código 100% cobertopor testes!

Page 46: Testing sucks

• JSCoverage

• CoverJS

Page 47: Testing sucks

Tudo é testável

• Complexidade vs Criticidade

• window.location.replace()

Page 48: Testing sucks

Testes em JavaScript

JS

Page 49: Testing sucks

Testes

Unitários

FuncionaisInterface

IntegraçãoDesempenho

Page 50: Testing sucks

Open Web

vários ambientes

Page 51: Testing sucks

Chrome

Firefox

Opera

IE 8, 9[, 10, ...]

Page 52: Testing sucks

Chrome

Firefox

Opera

IE 8, 9[, 10, ...]

Mobile

Page 53: Testing sucks

PhantomJS

Webkit

Page 54: Testing sucks

Ferramentas

QUnit

JasmineMocha

NodeUnit

Vows

Page 55: Testing sucks

Estilos de Testes

TDD BDD Exports

Page 56: Testing sucks

module( "Basics" );

test( "hello test", function() {  ok( 1 == "1", "Passed!" );});

http://qunitjs.com/

TDD

Page 57: Testing sucks

module( "Basics" );

test( "hello test", function() {  ok( 1 == "1", "Passed!" );});

http://qunitjs.com/

TDD

Page 58: Testing sucks

module( "Basics" );

test( "hello test", function() {  ok( 1 == "1", "Passed!" );});

http://qunitjs.com/

TDD

Page 59: Testing sucks

module( "Basics" );

test( "hello test", function() {  ok( 1 == "1", "Passed!" );});

http://qunitjs.com/

TDD

Page 60: Testing sucks

module( "Basics" );

test( "hello test", function() {  ok( 1 == "1", "Passed!" );});

http://qunitjs.com/

TDD

Page 61: Testing sucks

module( "Basics" );

test( "hello test", function() {  ok( 1 == "1", "Passed!" );});

http://qunitjs.com/

TDD

Page 62: Testing sucks

module( "Basics" );

test( "hello test", function() {  ok( 1 == "1", "Passed!" );});

http://qunitjs.com/

TDD

Page 63: Testing sucks

module( "Basics" );

test( "hello test", function() {  ok( 1 == "1", "Passed!" );});

http://qunitjs.com/

TDD

Page 64: Testing sucks

module( "Basics" );

test( "hello test", function() {  ok( 1 == "1", "Passed!" );});

http://qunitjs.com/

TDD

Page 65: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 66: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 67: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 68: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 69: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 70: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 71: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 72: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 73: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 74: Testing sucks
Page 75: Testing sucks

describe("A suite", function() { it("spec with an expectation",

function(){ expect(true).toBe(true); });

});

BDD

Page 76: Testing sucks

describe("A suite", function() { it("spec with an expectation",

function(){ expect(true).toBe(true); });

});

BDD

Page 77: Testing sucks

describe("A suite", function() { it("spec with an expectation",

function(){ expect(true).toBe(true); });

});

BDD

Page 78: Testing sucks

describe("A suite", function() { it("spec with an expectation",

function(){ expect(true).toBe(true); });

});

BDD

Page 79: Testing sucks

describe("A suite", function() { it("spec with an expectation",

function(){ expect(true).toBe(true); });

});

BDD

Page 80: Testing sucks

describe("A suite", function() { it("spec with an expectation",

function(){ expect(true).toBe(true); });

});

BDD

Page 81: Testing sucks

Exports

module.exports = { test1: function (test) { test.equals(this.foo, 'bar'); test.done(); }};

Page 82: Testing sucks

Exports

module.exports = { test1: function (test) { test.equals(this.foo, 'bar'); test.done(); }};

Page 83: Testing sucks

Exports

module.exports = { test1: function (test) { test.equals(this.foo, 'bar'); test.done(); }};

Page 84: Testing sucks

Exports

module.exports = { test1: function (test) { test.equals(this.foo, 'bar'); test.done(); }};

Page 85: Testing sucks

Exports

module.exports = { test1: function (test) { test.equals(this.foo, 'bar'); test.done(); }};

Page 86: Testing sucks

Como começar?

Page 87: Testing sucks

HTML Estático

JavaScript

Testes

Page 88: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <div id="qunit-fixtures"> <div id="foo">bar</div> </div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 89: Testing sucks

<!DOCTYPE html><html><head>  <meta charset="utf-8">  <title>QUnit Example</title>  <link rel="stylesheet" href="/t/qunit.css"></head><body>  <div id="qunit"></div>  <div id="qunit-fixtures"> <div id="foo">bar</div> </div>  <script src="/t/qunit.js"></script> <script src="/js/script.js"></script>  <script src="/t/unit/tests.js"></script></body></html>

Page 90: Testing sucks

Código testado tem bom desempenho?

• Testes unitários não medem desempenho

• Existem testes de desempenho

• Código sem erros pode evitar lentidão

Page 91: Testing sucks

DexterJS

Page 92: Testing sucks

Dexter.spy

Page 93: Testing sucks

http://jsbin.com/osijuq/7/edit

function carly( crazy ) { if ( typeof ( crazy ) === 'number' ) { return 'Call me maybe?'; } else { return 'Hey, I just met you!, and this is ' + crazy; }}

function meSad( maybe ) { return carly( maybe ? 5555555 : 'crazy!' );}

Page 94: Testing sucks

http://jsbin.com/osijuq/7/edit

function carly( crazy ) { if ( typeof ( crazy ) === 'number' ) { return 'Call me maybe?'; } else { return 'Hey, I just met you!, and this is ' + crazy; }}

function meSad( maybe ) { return carly( maybe ? 5555555 : 'crazy!' );}

Page 95: Testing sucks

http://jsbin.com/osijuq/7/edit

function carly( crazy ) { if ( typeof ( crazy ) === 'number' ) { return 'Call me maybe?'; } else { return 'Hey, I just met you!, and this is ' + crazy; }}

function meSad( maybe ) { return carly( maybe ? 5555555 : 'crazy!' );}

Page 96: Testing sucks

http://jsbin.com/osijuq/7/edit

function carly( crazy ) { if ( typeof ( crazy ) === 'number' ) { return 'Call me maybe?'; } else { return 'Hey, I just met you!, and this is ' + crazy; }}

function meSad( maybe ) { return carly( maybe ? 5555555 : 'crazy!' );}

Page 97: Testing sucks

http://jsbin.com/osijuq/7/edit

function carly( crazy ) { if ( typeof ( crazy ) === 'number' ) { return 'Call me maybe?'; } else { return 'Hey, I just met you!, and this is ' + crazy; }}

function meSad( maybe ) { return carly( maybe ? 5555555 : 'crazy!' );}

Page 98: Testing sucks

http://jsbin.com/osijuq/7/edit

function carly( crazy ) { if ( typeof ( crazy ) === 'number' ) { return 'Call me maybe?'; } else { return 'Hey, I just met you!, and this is ' + crazy; }}

function meSad( maybe ) { return carly( maybe ? 5555555 : 'crazy!' );}

Page 99: Testing sucks

http://jsbin.com/osijuq/7/edit

function carly( crazy ) { if ( typeof ( crazy ) === 'number' ) { return 'Call me maybe?'; } else { return 'Hey, I just met you!, and this is ' + crazy; }}

function meSad( maybe ) { return carly( maybe ? 5555555 : 'crazy!' );}

Page 100: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 101: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 102: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 103: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 104: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 105: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 106: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 107: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 108: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 109: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 110: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 111: Testing sucks

test( 'carly()', 4, function() {

var spy = Dexter.spy( window, 'carly', function( arg1 ) {

equal( arg1, 'crazy!', 'me sad got crazy!' );

});

meSad( false );

equal( spy.called, 1, 'carly was called once' );

spy.callback = 0;

equal( meSad( true ), 'Call me maybe?', 'keep asking' );

equal( spy.called, 2, 'carly called again!' );

spy.restore();

});

Page 112: Testing sucks
Page 113: Testing sucks

Dexter.stub

Page 114: Testing sucks

function carly( crazy ) { if ( typeof ( crazy ) === 'number' ) { return 'Call me maybe?'; } else { return 'Hey, I just met you!, and this is ' + crazy; }}

function meSad( maybe ) { return carly( maybe ? 5555555 : 'crazy!' );}

Page 115: Testing sucks

test( 'stubbed carly()', 1, function() { var stub = Dexter.stub( window, 'carly', function() { return 'relax'; }); equal( meSad( true ), 'relax', 'stubbed carly!' ); stub.restore();});

Page 116: Testing sucks

test( 'stubbed carly()', 1, function() { var stub = Dexter.stub( window, 'carly', function() { return 'relax'; }); equal( meSad( true ), 'relax', 'stubbed carly!' ); stub.restore();});

Page 117: Testing sucks

test( 'stubbed carly()', 1, function() { var stub = Dexter.stub( window, 'carly', function() { return 'relax'; }); equal( meSad( true ), 'relax', 'stubbed carly!' ); stub.restore();});

Page 118: Testing sucks

test( 'stubbed carly()', 1, function() { var stub = Dexter.stub( window, 'carly', function() { return 'relax'; }); equal( meSad( true ), 'relax', 'stubbed carly!' ); stub.restore();});

Page 119: Testing sucks

test( 'stubbed carly()', 1, function() { var stub = Dexter.stub( window, 'carly', function() { return 'relax'; }); equal( meSad( true ), 'relax', 'stubbed carly!' ); stub.restore();});

Page 120: Testing sucks

test( 'stubbed carly()', 1, function() { var stub = Dexter.stub( window, 'carly', function() { return 'relax'; }); equal( meSad( true ), 'relax', 'stubbed carly!' ); stub.restore();});

Page 121: Testing sucks

test( 'stubbed carly()', 1, function() { var stub = Dexter.stub( window, 'carly', function() { return 'relax'; }); equal( meSad( true ), 'relax', 'stubbed carly!' ); stub.restore();});

Page 122: Testing sucks
Page 123: Testing sucks

Dexter.fakeXHR

Page 124: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 125: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 126: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 127: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 128: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 129: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 130: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 131: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 132: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 133: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 134: Testing sucks

test( 'a fakeXHR', 2, function() { var fakeXHR = Dexter.fakeXHR(); $.get( '/ajax.url', function() { ok( true, 'ajax completed' ); });

equal( fakeXHR.requests.length, 1, 'requests === 1' );

fakeXHR.respond({ body : 'this is the ajax returned text', headers : { foo2 : 'bar2' }, status : 200 });});

Page 135: Testing sucks

Começar a criar testes?

Page 136: Testing sucks

Experimente!

Page 137: Testing sucks

• Coding Dojo

• Inicialize um projeto com o GruntJS

• TDD - Kent Back

• Engenharia de Software - Roger S Pressman

• Testable JavaScript - Mark Ethan Trostler *

Referências

Page 138: Testing sucks
Page 139: Testing sucks

Obrigado!

• @garu_rj

• @blabos

• @aoqfonseca

JS@[email protected]

http://search.cpan.org/~leobalter/