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

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 Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 Takeoffsammart93
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
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)wesley chun
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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 Scriptwesley chun
 

Recently uploaded (20)

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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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)
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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