SlideShare a Scribd company logo
1 of 76
Download to read offline
TEST-DRIVEN JAVASCRIPT
                            Für mehr Qualität in JavaScript-Applikationen




Wednesday, January 23, 13
WER BIN ICH?

    • Sebastian             Springer

    • 30

    • Dipl. Inf. (FH)

    • Teamleiter             @ Mayflower München

    • Nebenbei: JavaScript-Entwickler

    • @basti_springer

Wednesday, January 23, 13
WAS ERWARTET EUCH?




                                 ?
Wednesday, January 23, 13
WAS ERWARTET EUCH?

    • Was           ist TDD?




                                 ?
Wednesday, January 23, 13
WAS ERWARTET EUCH?

    • Was           ist TDD?




                                 ?
    • Warum TDD?




Wednesday, January 23, 13
WAS ERWARTET EUCH?

    • Was           ist TDD?




                                          ?
    • Warum TDD?

    • Was           benötige ich dafür?




Wednesday, January 23, 13
WAS ERWARTET EUCH?

    • Was           ist TDD?




                                          ?
    • Warum TDD?

    • Was           benötige ich dafür?
    • Wie           funktioniert’s?




Wednesday, January 23, 13
WAS
 IST
 TDD?
    WARUM
 TDD?
    VORAUSSETZUNGEN?
    WIE
 FUNKTIONIERT’S?



Wednesday, January 23, 13
WAS IST TDD?
    • Angewandtes            Softwaredesign und -entwicklung

    • Erst Tests, dann         den Code

    • Red, Green, Refactor

    • Clean            Code that works




Wednesday, January 23, 13
TDD
 ist
 doof

Wednesday, January 23, 13
DIE SCHATTENSEITEN
  • Verständnis

  • Disziplin               und Konsequenz

  • Einstiegshürde

  • Anfänglich               langsame Geschwindigkeit




Wednesday, January 23, 13
WAS
 IST
 TDD?   ✓
    WARUM
 TDD?
    VORAUSSETZUNGEN?
    WIE
 FUNKTIONIERT’S?



Wednesday, January 23, 13
Weil’s
 geht!

Wednesday, January 23, 13
Das Problem verstehen




Wednesday, January 23, 13
Sicherheit für Refactorings




Wednesday, January 23, 13
Schnelles Feedback




Wednesday, January 23, 13
Software muss getestet werden




Wednesday, January 23, 13
Software muss getestet werden
                            entweder manuell oder automatisch




Wednesday, January 23, 13
Dokumentation




Wednesday, January 23, 13
Basis für Weiterentwicklung




Wednesday, January 23, 13
Besserer Code




Wednesday, January 23, 13
Weniger Bugs




Wednesday, January 23, 13
Spaß an der Arbeit




Wednesday, January 23, 13
Qualität und Lauffähigkeit




Wednesday, January 23, 13
WAS
 IST
 TDD?   ✓
    WARUM
 TDD?                                      ✓
    VORAUSSETZUNGEN?
    WIE
 FUNKTIONIERT’S?



Wednesday, January 23, 13
IDE




Wednesday, January 23, 13
FRAMEWORK




Wednesday, January 23, 13
BROWSER




Wednesday, January 23, 13
Gibt’s
 das
 nicht
 in
 
            besser?
Wednesday, January 23, 13
INTEGRATION




Wednesday, January 23, 13
INTEGRATION



                             JsTestDriver Plugin




Wednesday, January 23, 13
JSTESTDRIVER




Wednesday, January 23, 13
+   =   ♥

Wednesday, January 23, 13
WAS
 IST
 TDD?   ✓
    WARUM
 TDD?                                      ✓
    VORAUSSETZUNGEN?                                                                 ✓
    WIE
 FUNKTIONIERT’S?



Wednesday, January 23, 13
DAS BEISPIEL:
                             FIZZ BUZZ



Wednesday, January 23, 13
FIZZ BUZZ

    • Es       wird eine Zahl eingegeben.

    • Ist      die Zahl durch 3 teilbar, ist das Ergebnis “fizz”.

    • Ist      die Zahl durch 5 teilbar, ist das Ergebnis “buzz”.

    • Ist  die Zahl sowohl durch 3 als auch durch 5 teilbar, ist das
        Ergebnis “fizzbuzz”.


Wednesday, January 23, 13
FIZZ BUZZ
         1                  1      11   11        21   fizz
         2                  2      12   fizz       22   22
         3                  fizz    13   13        23   23
         4                  4      14   14        24   fizz
         5                  buzz   15   fizzbuzz   25   buzz
         6                  fizz    16   16        26   26
         7                  7      17   17        27   fizz
         8                  8      18   fizz       28   28
         9                  fizz    19   19        29   29
         10                 buzz   20   buzz      30   fizzbuzz


Wednesday, January 23, 13
SETUP




Wednesday, January 23, 13
FIZZBUZZ.JSTD

                             load:
                               - lib/jasmine.js
                               - lib/JasmineAdapter.js
                               - spec/FizzBuzz.spec.js
                               - src/FizzBuzz.js




    • YAML-Format

    • Speicherorte          der verschiedenen Dateien

Wednesday, January 23, 13
Wednesday, January 23, 13
Na
 dann
 mal
 los!

Wednesday, January 23, 13
TEST FIRST


    • Erst         den Test, dann den Quellcode

    • Anforderungen           in Test übersetzen

    • One            problem a time




Wednesday, January 23, 13
describe(FizzBuzz, function () {
      use strict;

              it(should return 1, if 1 is provided, function () {
                  expect(fizzbuzz(1)).toEqual(1);
              });

  });




Wednesday, January 23, 13
red


Wednesday, January 23, 13
EINFACHSTE LÖSUNG



    • Ziel: Der Test          muss grün werden.

    • Fokus            auf die aktuelle Problemstellung




Wednesday, January 23, 13
FAKE IT ‘TIL YOU MAKE IT


    • Umsetzung                mit fixen Werten

    • Tests          werden sehr schnell grün

    • Wenig                 Code

    • Kein          Over-Engineering



Wednesday, January 23, 13
var fizzbuzz = function () {
                                use strict;
                                return 1;
                            };




Wednesday, January 23, 13
green


Wednesday, January 23, 13
TRIANGULATION


    • Mehrere Tests          mit verschiedenen Werten

    • Klare           Implementierung

    • Saubere Abstraktion

    • Tests          mit Grenzwerten



Wednesday, January 23, 13
it(should return 2, if 2 is provided, function () {
             expect(fizzbuzz(2)).toEqual(2);
         });




Wednesday, January 23, 13

More Related Content

More from Sebastian Springer

Creating Enterprise Web Applications with Node.js
Creating Enterprise Web Applications with Node.jsCreating Enterprise Web Applications with Node.js
Creating Enterprise Web Applications with Node.jsSebastian Springer
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsSebastian Springer
 
From Zero to Hero – Web Performance
From Zero to Hero – Web PerformanceFrom Zero to Hero – Web Performance
From Zero to Hero – Web PerformanceSebastian Springer
 
Von 0 auf 100 - Performance im Web
Von 0 auf 100 - Performance im WebVon 0 auf 100 - Performance im Web
Von 0 auf 100 - Performance im WebSebastian Springer
 
ECMAScript 6 im Produktivbetrieb
ECMAScript 6 im ProduktivbetriebECMAScript 6 im Produktivbetrieb
ECMAScript 6 im ProduktivbetriebSebastian Springer
 
Große Applikationen mit AngularJS
Große Applikationen mit AngularJSGroße Applikationen mit AngularJS
Große Applikationen mit AngularJSSebastian Springer
 
Best Practices für TDD in JavaScript
Best Practices für TDD in JavaScriptBest Practices für TDD in JavaScript
Best Practices für TDD in JavaScriptSebastian Springer
 
Warum ECMAScript 6 die Welt ein Stückchen besser macht
Warum ECMAScript 6 die Welt ein Stückchen besser machtWarum ECMAScript 6 die Welt ein Stückchen besser macht
Warum ECMAScript 6 die Welt ein Stückchen besser machtSebastian Springer
 

More from Sebastian Springer (20)

Schnelleinstieg in Angular
Schnelleinstieg in AngularSchnelleinstieg in Angular
Schnelleinstieg in Angular
 
Creating Enterprise Web Applications with Node.js
Creating Enterprise Web Applications with Node.jsCreating Enterprise Web Applications with Node.js
Creating Enterprise Web Applications with Node.js
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
 
From Zero to Hero – Web Performance
From Zero to Hero – Web PerformanceFrom Zero to Hero – Web Performance
From Zero to Hero – Web Performance
 
Von 0 auf 100 - Performance im Web
Von 0 auf 100 - Performance im WebVon 0 auf 100 - Performance im Web
Von 0 auf 100 - Performance im Web
 
A/B Testing mit Node.js
A/B Testing mit Node.jsA/B Testing mit Node.js
A/B Testing mit Node.js
 
Angular2
Angular2Angular2
Angular2
 
Einführung in React
Einführung in ReactEinführung in React
Einführung in React
 
JavaScript Performance
JavaScript PerformanceJavaScript Performance
JavaScript Performance
 
ECMAScript 6 im Produktivbetrieb
ECMAScript 6 im ProduktivbetriebECMAScript 6 im Produktivbetrieb
ECMAScript 6 im Produktivbetrieb
 
Streams in Node.js
Streams in Node.jsStreams in Node.js
Streams in Node.js
 
JavaScript Performance
JavaScript PerformanceJavaScript Performance
JavaScript Performance
 
Große Applikationen mit AngularJS
Große Applikationen mit AngularJSGroße Applikationen mit AngularJS
Große Applikationen mit AngularJS
 
Testing tools
Testing toolsTesting tools
Testing tools
 
Node.js Security
Node.js SecurityNode.js Security
Node.js Security
 
Typescript
TypescriptTypescript
Typescript
 
Reactive Programming
Reactive ProgrammingReactive Programming
Reactive Programming
 
Best Practices für TDD in JavaScript
Best Practices für TDD in JavaScriptBest Practices für TDD in JavaScript
Best Practices für TDD in JavaScript
 
Warum ECMAScript 6 die Welt ein Stückchen besser macht
Warum ECMAScript 6 die Welt ein Stückchen besser machtWarum ECMAScript 6 die Welt ein Stückchen besser macht
Warum ECMAScript 6 die Welt ein Stückchen besser macht
 
Lean Startup mit JavaScript
Lean Startup mit JavaScriptLean Startup mit JavaScript
Lean Startup mit JavaScript
 

Recently uploaded

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Recently uploaded (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

Webinar Test-Driven JavaScript