Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lightning Talk: Testes em Javascript

Duke
July 27, 2015

Lightning Talk: Testes em Javascript

Duke

July 27, 2015
Tweet

More Decks by Duke

Other Decks in Programming

Transcript

  1. Testes em javascript

    View full-size slide

  2. Duke
    dukex.github.io
    github.com/dukex
    twitter.com/_dukex

    View full-size slide

  3. Testes em javascript

    View full-size slide

  4. TDD
    test('equals 1 for sets of zero length ', function() {
    assert.equal(1, factorial(0));
    });
    test('equals 1 for sets of length one ', function() {
    assert.equal(1, factorial(1));
    });
    test('equals 2 for sets of length two ', function() {
    assert.equal(2, factorial(2));
    });
    test('equals 6 for sets of length three ', function() {
    assert.equal(6, factorial(3));
    });

    View full-size slide

  5. Em contraste com TDD, BDD é quando escrevemos
    comportamento e especificação que então impulsiona o nosso
    desenvolvimento de software. Comportamento e especificações
    pode parecer muito semelhante aos testes, mas a diferença é
    muito sutil e importante.
    https://joshldavis.com/2013/05/27/difference-between-tdd-and-bdd/

    View full-size slide

  6. BDD
    it('should return 1 when given 0 ', function() {
    factorial(0).should.equal(1);
    });
    it('should return 1 when given 1 ', function() {
    factorial(1).should.equal(1);
    });
    it('should return 2 when given 2 ', function() {
    factorial(2).should.equal(2);
    });
    it('should return 6 when given 3 ', function() {
    factorial(3).should.equal(6);
    });

    View full-size slide

  7. BDD
    feature('Calculator: add')
    .scenario('should be able to add 2 numbers together
    ')
    .when('I enter "1"')
    .and('I add "2"')
    .then('I should get "3"')
    .scenario('should be able to add 3 numbers together
    ')
    .when('I enter "1"')
    .and('I add "2"')
    .and('I add "3"')
    .then('I should get "6"')

    View full-size slide

  8. Mão na massa...
    pull-request https://github.com/gdg-
    sp/html5studygroup/pull/20

    View full-size slide

  9. 1. Crei a pasta 'test' no projeto
    2. Instalei o mocha (npm install --save mocha)
    3. Instalei o chai (npm install --save chai)
    4. Instalei o supertest (npm install supertest --save-dev)
    5. Criei arquivo 'test/server_test.js'
    6. Movi código necesario para app.js (código testavel)
    7. Comentei codigo não testado
    8. Testei

    View full-size slide

  10. Links
    ➔ https://joshldavis.com/2013/05/27/difference-between-tdd-and-
    bdd/
    ➔ https://github.com/jdavis/tdd-vs-bdd
    ➔ http://programmers.stackexchange.com/questions/135218/what-is-
    the-difference-between-writing-test-cases-for-bdd-and-tdd
    ➔ https://github.com/visionmedia/supertest
    ➔ http://code.tutsplus.com/tutorials/how-to-test-your-javascript-
    code-with-qunit--net-9077

    View full-size slide

  11. Obrigado!
    dukex.github.io
    github.com/dukex
    twitter.com/_dukex
    bit.ly/meetup-8

    View full-size slide