fe05 test drivenjavascriptdevelopment

Post on 24-May-2015

43 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Template designed by

T.D.J.D.: Test Driven Javascript Development

Antonio Turibbio Liccardiantonio.liccardi@dotnetcampania.orgwww.dotnetcampania.org/blogs/turibbiowww.getlatestversion.it

Template designed by

Template designed by

brought to you by

Template designed by

Unit Testing, TDD e TDJD

Qunit

Metriche

Automazione

Considerazioni

Agenda

Template designed by

Il motivo principale per scrivere unit test è il

dimostrare la correttezza di una funzionalità

A cosa serve lo unit testing?

Template designed by

Ma scrivere unit test non sempre implica direttamente che il nostro codice sia

migliore!

A cosa serve lo unit testing?

Template designed by

Ci può aiutare però a renderlo più

testabile, pulito, riutilizzabile

A cosa serve lo unit testing?

Template designed by

Scritti dagli sviluppatori

Isolamento

Atomici

Costituiscono una documentazione vivente

Facilitano la gestione della anomalie (regression)

Automazione

Caratteristiche dello unit testing

Template designed by

Svantaggi: E’ un processo costoso

Richiede tempo, pazienza

e soprattutto bravura

Javascript Testing

perché?

Template designed by

Alert UAT

Debug

Come testiamo il nostro javascript?

Template designed by

Come testiamo il nostro javascript?

Template designed by

Come testiamo il nostro javascript

Richiede tempo

Conduce ad errori

Non riproducibile

Template designed by

Cross-browser testing

Template designed by

E quindi?

Lo unit test ci fa bene…

…soprattutto se lo facciamo nel modo

giusto

Template designed by

Test Driven Development

Template designed by

«no big design up front»

Test Driven Development

Template designed by

Think

Write a test

Run the test

Make the test pass

Refactor

Come funziona?

Template designed by

You ain’t gonna need it! (YAGNI)

Don’t repeat yourself (DRY)

Descriptive and Meaningful Phrases (DAMP)

SOLID

Refactoring

Certain structures in code suggest (sometimes they scream for) the possibility of refactoring

Martin Fowler

Template designed by

Organizzare un test

Fixture Test Case Check

Template designed by

Organizzare unit test

AAA

• Arrange• Act• Assert

BDD

• Given• When• Then

4 Phase

• Setup• Exercise• Verify• Teardow

n

Template designed by

Come funzionano?

Unit Test Framework

Unit Test Runner Unit Test Codice Risultati

Template designed by

Nasce dall’idea degli xUnit Frameworks

E’ stato realizzato dal team da John Resig

Può testare codice server side js

Cosa è QUnit

https://github.com/jquery/qunit

Template designed by

Test Runner

Assertions

In-Browser Testing

Plugin

QUnit

dem

o Qunit

Template designed by

Pete Hodgson

http://bit.ly/19wDtTp

Martin Fowler

http://bit.ly/1hDeP1O

Segregated DOM

Template designed by

Test doubles

Template designed by

Dummy Fake

Stub Spy

Mock

Test doubles

Template designed by

Test doubles nella vita reale

StateVerificatio

n

BehaviorVerificatio

n

Mocks aren’t stubs! (Fowler: http://bit.ly/18BPLE1)

Template designed by

Sinon.js

Spies

Stubs

Mocks

Fake Timers

Fake XHR

Fake server

JSON-P

Assertions

Matchers

Sandboxing

dem

o Sinon.js

Template designed by

In-Browser testing vs Headless Testing

Template designed by

JSTestDriver

Template designed by

TestSwarm

dem

o phantomJS

Template designed by

E’ una percentuale che indica il numero di unit test correlati ai metodi del nostro codice

Code coverage

dem

o blanket.js

Template designed by

Come automatizzare i nostri test?

Continuous integration

dem

o chutzpah

Template designed by

Logica UI != Logica applicativa

Evitare singleton

Scrivere metodi piccoli

Testare i casi limite

Isolare dall’esterno

Suddividere logicamente il proprio codice

Come scrivere test

Template designed by

Riferimenti

Template designed by

Grazie!

top related