UNIT TESTING? FOR THE REST OF US                  VLAD ILIESCU                     MAXCODE             26 NOVEMBER 2011
INTRO                 SIMPLE DEMO      UNIT TESTING?GUIDELINES                 ADVANCED DEMO  JAVASCRIPT               JAV...
UNIT TESTING?
WHY?
HOW?
NO, REALLY – HOW?
QUESTIONS?
GUIDELINES
A TEST SHOULD BE            FAST
A TEST SHOULD BE    INDEPENDENT
A TEST SHOULD BE        ISOLATED
A TEST SHOULD BESELF-DESCRIPTIVE
HOW DO I WRITETESTABLE CODE?
QUESTIONS?
WHYJAVASCRIPT?
BECAUSE OFSPIDER-MAN
HOW?
NO, REALLY - HOW?
QUESTIONS?
HTTP://MSDN.MICROSOFT.COM/EN-US/LIBRARY/MS243147.ASPX      HTTP://MSDN.MICROSOFT.COM/EN-US/LIBRARY/MS182530.ASPX          ...
COOL KIDS FILL THE EVALUATION FORM
THANKS FOR LISTENING!                   VLAD ILIESCU                 VLADILIESCU.RO
Upcoming SlideShare
Loading in...5
×

Codecamp iasi-26 nov 2011-unit-testing-for-the-rest-of-us

602

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
602
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • AGENDAIntroducere (why/how)Demo simplu (OPTIONAL)GuidelinesDemo avansat (IOC)Introtestare in JavascriptDemo Javascript
  • Unit testing-ul se refera la testarea automata (prin cod) a unorbucati de cod.Existamaimultetipuri de teste in afara de unit tests: integration tests (testeazafelul in care lucreazaimpreunamaimulte module ale aplicatiei), performance tests (cat de repederuleazaanumitebucati de cod), load tests (cat de bine functioneazaaplicatiaatuncicandcrestenivelul de incarcare al acesteia). Prin unit test intelegem un test care testeaza o unitate, ceamai mica bucata de funtionalitatepe care o putemtesta. De obiceiastainseamna o clasa - in mod ideal artrebuisaputemsatestamfiecareclasa in mod izolat, fara a ne atinge de dependinteleeiexterne.
  • Asigura o plasa de siguranta in cazul schimbarilor (detaliat cazul refactoring-ului proposal-urilor).Documenteaza codul - examinand un unit test, putem vedea cum se foloseste codul pe care acesta il testeaza.Design - daca o metoda e greu de testat, poate indica o problema cu design-ul acesteia. Poate metoda incearca sa faca prea mult, poate ar trebui extrase dependintele externe, etc.Cum testele sunt rulate de calculator, ele se executa mult mai repede si pot fi rulate in mod repetat - devine mult mai usor sa prindem erorile introduse.
  • Setup, Run, AssertUn test consta din acesti 3 pasi. Initial definimpreconditiile (setup), apoirulamcodulpe care vremsailtestam (run), dupa care verificamexactitatearezultatelor (assert).
  • demo
  • Un test ar trebui sa ruleze repede pentru ca se va executa de multe ori. daca testele nu sunt rapide, echipa nu o sa le ruleze.
  • Rezultateleunui test nu artrebuisadepinda de cealteteste s-au rulatinainteaacestuia. Inclusivvariabilelepartajate de maimultetesteartrebuiinitializate de fiecare data, pentru a se evitarezultateneasteptate.
  • Un test nu artrebuisadepinda de fisiereexterne, baze de date, servere de email, data siora, web service-uri, etc.El artrebuisatestezelogica. Dependinteleexterneartrebuisa fie simulate.Un test poatesatesteze in mod explicit interactiunea cu fisiereexterne, baze de date, servere de email, web service-uri, etc. Dar atuncidevine o altacategorie de test, e integration test.
  • Numelemetodelortrebuiesadescrieclarce se testeaza.Cand un test pica, trebuiesa fie usor de intelesce nu functioneaza.Casaintelegcetesteaza testAssignMembership1(), testAssignMembership2() artrebuisainspectezcodullor.
  • In primul rand nu testez tot, doar codul care contine logica si pe care ma astept sa il modific in viitor.Single Responsibility Principle si Dependency Injection O clasaartrebuisafaca un singurlucru. Logicaaditionala o scoatem in afara, in dependinte, pe care le injectam.In felulasta, un test poatetesta un singurlucru, iardependintele pot fi simulate prin mocks si stubs Stubs - clase helper scrise de noi care implementeazainterfetelefolosite de codultestatsi care nu facnimic, Mocks - clase care implementeazainterfetelefolosite de codultestat, dar care continsilogica de testare a comportamentului - ex, de cateori s-a apelat o anumitametoda, ordinealor de apel, etc. Personal, prefer stubs pentrucaaltfeltestelestiupreamultedesprecodultestatsidevinastfelfoarte fragile (la oricemodificare in codultestat, eleriscasa crape).
  • Folosim din ce in cemaimult javascript in aplicatiilenoastre, siimplementam din ce in cemaimultalogica in el. In plus limbajul nu e precompilat, decinicimacar nu stimsigurca tot codulscrisvaputea fi executat cu succes.Asadar,risculintroducerii de eroricrestedestul de mult. Daca am testamacarzonelemai intensive din punct de vedere al logicii, am reduce o parte din problemeleacestea.
  • With great power comes great responsibilit
  • QUnitestelibrariafolosita de proiectul jQuery pentru a isitestacodul. Este unul din celemaipopulare framework-uri de testare javascript. Are un apidestul de simplusiusor de folosit. Nu se integreaza implicit cu aplicatiiconsola, darofera un mod standard de prezentare a rezultatelor.
  • demo
  • Codecamp iasi-26 nov 2011-unit-testing-for-the-rest-of-us

    1. 1. UNIT TESTING? FOR THE REST OF US VLAD ILIESCU MAXCODE 26 NOVEMBER 2011
    2. 2. INTRO SIMPLE DEMO UNIT TESTING?GUIDELINES ADVANCED DEMO JAVASCRIPT JAVASCRIPT DEMO
    3. 3. UNIT TESTING?
    4. 4. WHY?
    5. 5. HOW?
    6. 6. NO, REALLY – HOW?
    7. 7. QUESTIONS?
    8. 8. GUIDELINES
    9. 9. A TEST SHOULD BE FAST
    10. 10. A TEST SHOULD BE INDEPENDENT
    11. 11. A TEST SHOULD BE ISOLATED
    12. 12. A TEST SHOULD BESELF-DESCRIPTIVE
    13. 13. HOW DO I WRITETESTABLE CODE?
    14. 14. QUESTIONS?
    15. 15. WHYJAVASCRIPT?
    16. 16. BECAUSE OFSPIDER-MAN
    17. 17. HOW?
    18. 18. NO, REALLY - HOW?
    19. 19. QUESTIONS?
    20. 20. HTTP://MSDN.MICROSOFT.COM/EN-US/LIBRARY/MS243147.ASPX HTTP://MSDN.MICROSOFT.COM/EN-US/LIBRARY/MS182530.ASPX HTTP://DOCS.JQUERY.COM/QUNIT HTTPS://GITHUB.COM/JQUERY/QUNIT HTTP://MSDN.MICROSOFT.COM/EN-US/SCRIPTJUNKIE/GG749824 HTTP://HTML5BOILERPLATE.COMHTTP://GOOGLETESTING.BLOGSPOT.COM/2008/07/HOW-TO-WRITE-3V1L- UNTESTABLE-CODE.HTML
    21. 21. COOL KIDS FILL THE EVALUATION FORM
    22. 22. THANKS FOR LISTENING! VLAD ILIESCU VLADILIESCU.RO
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×