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

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

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Webinar Test-Driven JavaScript