SlideShare uma empresa Scribd logo
1 de 55
Baixar para ler offline
Javascript Testing


Sebastian Springer I 10. Oktober 2011




                                        © Mayflower GmbH 2010
That's me



I   Diplom-Informatiker (FH)
I   Zend Certified Developer
I   Certified Oracle MySQL Developer
I   Scrum Master
                                              HI!
                                        MY NAME IS
                                       Sebastian Springer



                                                            Mayflower GmbH I 2
Javascript Testing




                     ©
Agenda



I   Warum Testing?
I   Unittests
I   Integrationtests
I   Automatisierung




                          ©SPH




                       Mayflower GmbH I 4
Warum Testing?




                    ©姒儿喵喵
                 Mayflower GmbH I 5
Warum Testing?



I   Sicherheit
I   Refactoring
I   Continuous Integration
I   Dokumentation




                             Mayflower GmbH I 6
Testing – Voraussetzungen




                               ©姒儿喵喵
                            Mayflower GmbH I 7
Testing – Voraussetzungen



I   Keine Hindernisse
I   Know-how
I   Testbarer Code




                            Mayflower GmbH I 8
Und warum Javascript?




                           ©姒儿喵喵
                        Mayflower GmbH I 9
Und warum Javascript?



I   Wachsende Bedeutung
I   User Experience
I   Mehr Logik
I   Mehr LoC
    ·Applikation vor 4 Jahren: ca. 3% Javascript
    ·Aktuelle Applikation: ca. 43% Javascript




                                                   Mayflower GmbH I 10
Unittests




            Mayflower GmbH I 11
Unittest Frameworks




                          © BM5k

                      Mayflower GmbH I 12
Unittests – Frameworks




                     Nodeunit
  JSUnit                                           UnitTesting

                              QUnit

TestCase
                                  jsUnitTest


       J3Unit
                         D.O.H.                YUI Test

                                                                 Mayflower GmbH I 13
Unittests – Frameworks




                     Nodeunit
  JSUnit                                           UnitTesting


                              QUnit
TestCase
                                  jsUnitTest


       J3Unit
                         D.O.H.                YUI Test

                                                                 Mayflower GmbH I 14
Unittests – QUnit



<html>
    <head>
        <script   src="scripts/library/jquery.js"></script>
        <script   src="scripts/library/underscore.js"></script>
        <script   src="scripts/library/backbone.js"></script>
        <script   src="scripts/library/require.js"></script>

       <link rel="stylesheet" type="text/css" href="/style/style.css" />
       <link rel="stylesheet" type="text/css" href="/style/qunit.css" />

       <script src="/scripts/library/qunit.js"></script>




                                                                  Mayflower GmbH I 15
Unittests – QUnit



<script>
    require(['/scripts/application/models/ggt.js'], function(gcdClass) {
         var gcd = new gcdClass();

        module('Greatest Common Divisor');

        test("Check GCD Success, exact match", 1, function() {...});
        test("Check GCD Success, no match", 1, function() {...});
        test("Check GCD with Zero", 0, function() {...});
        test("This should Fail", function() {...});
    });
</script>




                                                             Mayflower GmbH I 16
Unittests – QUnit



    </head>
    <body>
        <h1 id="qunit-header">QUnit example</h1>
        <h2 id="qunit-banner"></h2>
        <div id="qunit-testrunner-toolbar"></div>
        <h2 id="qunit-userAgent"></h2>
        <ol id="qunit-tests"></ol>
        <div id="qunit-fixture">test markup, will be hidden</div>
    </body>
</html>




                                                             Mayflower GmbH I 17
Unittests – QUnit




                    Mayflower GmbH I 18
Unittests – QUnit Asserts



I   ok(state, msg)
I   equal(actual, expected, msg)
I   deepEqual(actual, expected, msg)
I   strictEqual(actual, expected, msg)
I   raises(block, expected, msg)


I   not...(..., msg)
    ·notEqual(actual, expected, msg)


                                         Mayflower GmbH I 19
Merkmale von Unittests




                         Mayflower GmbH I 20
Unittests – Isoliert



I   Isoliert




                       Mayflower GmbH I 21
Unittests – Isoliert



function doALotOfAjaxMagicAndTakeACallback(cb) {
    $.ajax({
        type: 'POST',
        dataType: 'json',
        data: '{}',
        contentType: 'application/json',
        url: 'my/backend',
        success: function(res) {
             var result = null;
             {...}
             return result;
        }
    });
}




                                                   Mayflower GmbH I 22
Unittests – Isoliert



test("Test my ajax magic", function() {

      stop();

      doALotOfAjaxMagicAndTakeACallback(
          function(result) {
              equals(result, "It's magic");

                start();
           }
      );
});




                                              Mayflower GmbH I 23
Unittests – Sinon.js



I   Test Spies
I   Stubs
I   Mocks
I   Fake Timers
I   Fake XHR und Server




                          Mayflower GmbH I 24
Unittests – Positiv/Negativ testing



I   Isoliert
I   Positiv/Negativ testing




                                      Mayflower GmbH I 25
Unittests – Positiv/Negativ testing



test("Check GCD", 1, function() {
      equal(3, gcd.calculate(15, 9));
});




                                        Mayflower GmbH I 26
Unittests – Positiv/Negativ testing



test("Check GCD Success, exact match", 1, function() {
    equal(2, gcd.calculate(4, 2));
});

test("Check GCD Success, no match", 1, function() {
    equal(3, gcd.calculate(15, 9));
});

test("Check GCD Success with Zero", 2, function() {
    equal(4, gcd.calculate(0, 4));
    equal(4, gcd.calculate(4, 0));
});

test("Check GCD Failure", 1, function() {
    equal(false, gcd.calculate('a', 'b'));
});




                                                         Mayflower GmbH I 27
Unittests – Häufige Ausführung



I   Isoliert
I   Positiv/Negativ testing
I   Häufige Ausführung




                                 Mayflower GmbH I 28
Unittests – Häufige Ausführung




                                 Mayflower GmbH I 29
Unittests – Blackbox testing



I   Isoliert
I   Positiv/Negativ testing
I   Häufige Ausführung
I   Blackbox testing – Input/Output




                                      Mayflower GmbH I 30
Unittests – Blackbox testing

/**
 * This method calculates the greatest common divisor
  * and returns the result
  *
  * @param m integer
  * @param n integer
  *
  * @return mixed integer result, false if invalid params
 */
calculate: function (m, n)
{
     if (typeof m != 'number' || typeof n != 'number') {
         return false;
     }
     if (n == 0) {
         return m;
     } else if (m == 0) {
         return n;
     } else {
         return this.calculate(n, m % n);
     }
}

                                                            Mayflower GmbH I 31
Unittests – Blackbox testing

/**
 * This method calculates the greatest common divisor
 * and returns the result
 *
 * @param m integer
 * @param n integer
 *
 * @return mixed integer result, false if invalid params
 */
calculate: function (m, n)
{...}




                                                           Mayflower GmbH I 32
Unittests – Test First



I   Isoliert
I   Positiv/Negativ testing
I   Häufige Ausführung
I   Blackbox testing – Input/Output
I   Test First/Test Parallel




                                      Mayflower GmbH I 33
Unittests – Test First


calculate: function (m, n)
{
    if (typeof m != 'number' || typeof n != 'number') {
        return false;
    }
    if (n == 0) {
        return m;
    } else if (m == 0) {
        return n;
    } else {
        return this.calculate(n, m % n);
    }
}

test(“Check GDC“, function() {
    // @TODO write testlogic
});




                                                          Mayflower GmbH I 34
Unittests – Test First


/**
 * This method calculates the greatest common divisor
  * and returns the result
  *
  * @param m integer
  * @param n integer
  *
  * @return mixed integer result, false if invalid params
 */
calculate: function (m, n)
{
     return 2;
}

test(“Check GDC Success, exact match“, function() {
    equal(2, gcd.calculate(4, 2));
});




                                                            Mayflower GmbH I 35
Testbarer Code




                 Mayflower GmbH I 36
Unittests – Voraussetzung: testbarer Code



I   Unabhängiger Code
I   Überschaubare Komplexität
I   Dependency Injection




                                            Mayflower GmbH I 37
Organisation




               Mayflower GmbH I 38
Unittests – Organisation



I   module()




I   test()




                           Mayflower GmbH I 39
Integrationtests




                   Mayflower GmbH I 40
Organisation




                   © Potatojunkie

               Mayflower GmbH I 41
Integrationtests – Selenium IDE




                                  Mayflower GmbH I 42
Integrationtests – Häufig verwendete Kommandos



I   waitFor...
    ·z.B. waitForElementPresent
I   verify...
    ·z.B. verifyTextPresent
I click
I type
I ...




                                                 Mayflower GmbH I 43
Locators




           Mayflower GmbH I 44
Integrationtests – Selenium IDE




                                  Mayflower GmbH I 45
Integrationtests – Locators



I   identifier=username
I   id=password
I   name=username
I   dom=document.forms[0]
I   xpath=//form[@id='loginForm']/div[1]/input[1]
I   link=myLinkText
I   css=div#loginBox




                                                    Mayflower GmbH I 46
Integrationtests – Variablen und Testsuites




                                              Mayflower GmbH I 47
Selenium




           Stabilität?       © andyarthur

                         Mayflower GmbH I 48
Automatisierung




                  Mayflower GmbH I 49
Automatisierung




                  Mayflower GmbH I 50
Automatisierung


                         SVN Commit



                             Jenkins CI




                  Selenium                QUnit




                                                  Mayflower GmbH I 51
Automatisierung – Selenium


                             phpunit
                                       selenseDirectory

                     Selenium RC/grid
                        Selenium RC



                  Browser
                 Browser
                 Browser
                 Browser

                                        Jenkins



                                                          Mayflower GmbH I 52
Automatisierung – QUnit


                            QUnit



                          jsTestDriver



                  Browser
                 Browser
                 Browser
                 Browser

                                         Jenkins



                                                   Mayflower GmbH I 53
Fragen?


© br1dotcom




                    Mayflower GmbH I 54
Vielen Dank für Ihre Aufmerksamkeit!




        Kontakt   Sebastian Springer
                  sebastian.springer@mayflower.de
                  +49 89 242054 1120


                  Mayflower GmbH
                  Mannhardtstrasse 6
                  80538 München

14.10.2011                              Mayflower GmbH   55

Mais conteúdo relacionado

Semelhante a Javascript Testing Guide

Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMockYing Zhang
 
Upstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingUpstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingDanWooster1
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Fwdays
 
Testing in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinTesting in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinSigma Software
 
One-Click Deployment with Jenkins
One-Click Deployment with JenkinsOne-Click Deployment with Jenkins
One-Click Deployment with JenkinsMayflower GmbH
 
31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdfgauravavam
 
Case Studies in Terrible Testing
Case Studies in Terrible TestingCase Studies in Terrible Testing
Case Studies in Terrible TestingTodd Gardner
 
Google mock training
Google mock trainingGoogle mock training
Google mock trainingThierry Gayet
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in JavaMichael Fons
 
E2E testing con nightwatch.js - Drupalcamp Spain 2018
E2E testing con nightwatch.js  - Drupalcamp Spain 2018E2E testing con nightwatch.js  - Drupalcamp Spain 2018
E2E testing con nightwatch.js - Drupalcamp Spain 2018Salvador Molina (Slv_)
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronizationcscarcas
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaRavikiran J
 

Semelhante a Javascript Testing Guide (20)

JMockit
JMockitJMockit
JMockit
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Upstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingUpstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testing
 
Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"Никита Галкин "Testing in Frontend World"
Никита Галкин "Testing in Frontend World"
 
Testing in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita GalkinTesting in FrontEnd World by Nikita Galkin
Testing in FrontEnd World by Nikita Galkin
 
One-Click Deployment with Jenkins
One-Click Deployment with JenkinsOne-Click Deployment with Jenkins
One-Click Deployment with Jenkins
 
31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf
 
Case Studies in Terrible Testing
Case Studies in Terrible TestingCase Studies in Terrible Testing
Case Studies in Terrible Testing
 
Google mock training
Google mock trainingGoogle mock training
Google mock training
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in Java
 
Junit
JunitJunit
Junit
 
Unit Test Fun
Unit Test FunUnit Test Fun
Unit Test Fun
 
DevOps for PHP
DevOps for PHPDevOps for PHP
DevOps for PHP
 
E2E testing con nightwatch.js - Drupalcamp Spain 2018
E2E testing con nightwatch.js  - Drupalcamp Spain 2018E2E testing con nightwatch.js  - Drupalcamp Spain 2018
E2E testing con nightwatch.js - Drupalcamp Spain 2018
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 

Mais de Mayflower GmbH

Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...Mayflower GmbH
 
JavaScript Days 2015: Security
JavaScript Days 2015: SecurityJavaScript Days 2015: Security
JavaScript Days 2015: SecurityMayflower GmbH
 
Vom Entwickler zur Führungskraft
Vom Entwickler zur FührungskraftVom Entwickler zur Führungskraft
Vom Entwickler zur FührungskraftMayflower GmbH
 
Salt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native ClientSalt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native ClientMayflower GmbH
 
Plugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debuggingPlugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debuggingMayflower GmbH
 
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...Mayflower GmbH
 
Native Cross-Platform-Apps mit Titanium Mobile und Alloy
Native Cross-Platform-Apps mit Titanium Mobile und AlloyNative Cross-Platform-Apps mit Titanium Mobile und Alloy
Native Cross-Platform-Apps mit Titanium Mobile und AlloyMayflower GmbH
 
Pair Programming Mythbusters
Pair Programming MythbustersPair Programming Mythbusters
Pair Programming MythbustersMayflower GmbH
 
Shoeism - Frau im Glück
Shoeism - Frau im GlückShoeism - Frau im Glück
Shoeism - Frau im GlückMayflower GmbH
 
Bessere Software schneller liefern
Bessere Software schneller liefernBessere Software schneller liefern
Bessere Software schneller liefernMayflower GmbH
 
Von 0 auf 100 in 2 Sprints
Von 0 auf 100 in 2 SprintsVon 0 auf 100 in 2 Sprints
Von 0 auf 100 in 2 SprintsMayflower GmbH
 
Piwik anpassen und skalieren
Piwik anpassen und skalierenPiwik anpassen und skalieren
Piwik anpassen und skalierenMayflower GmbH
 
Agilitaet im E-Commerce - E-Commerce Breakfast
Agilitaet im E-Commerce - E-Commerce BreakfastAgilitaet im E-Commerce - E-Commerce Breakfast
Agilitaet im E-Commerce - E-Commerce BreakfastMayflower GmbH
 

Mais de Mayflower GmbH (20)

Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
Mit Maintenance umgehen können- Fixt du noch Bugs oder lieferst du schon neue...
 
Why and what is go
Why and what is goWhy and what is go
Why and what is go
 
Agile Anti-Patterns
Agile Anti-PatternsAgile Anti-Patterns
Agile Anti-Patterns
 
JavaScript Days 2015: Security
JavaScript Days 2015: SecurityJavaScript Days 2015: Security
JavaScript Days 2015: Security
 
Vom Entwickler zur Führungskraft
Vom Entwickler zur FührungskraftVom Entwickler zur Führungskraft
Vom Entwickler zur Führungskraft
 
Produktive teams
Produktive teamsProduktive teams
Produktive teams
 
Salt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native ClientSalt and pepper — native code in the browser Browser using Google native Client
Salt and pepper — native code in the browser Browser using Google native Client
 
Plugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debuggingPlugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debugging
 
Usability im web
Usability im webUsability im web
Usability im web
 
Rewrites überleben
Rewrites überlebenRewrites überleben
Rewrites überleben
 
JavaScript Security
JavaScript SecurityJavaScript Security
JavaScript Security
 
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
50 mal produktiver - oder warum ich gute Teams brauche und nicht gute Entwick...
 
Responsive Webdesign
Responsive WebdesignResponsive Webdesign
Responsive Webdesign
 
Native Cross-Platform-Apps mit Titanium Mobile und Alloy
Native Cross-Platform-Apps mit Titanium Mobile und AlloyNative Cross-Platform-Apps mit Titanium Mobile und Alloy
Native Cross-Platform-Apps mit Titanium Mobile und Alloy
 
Pair Programming Mythbusters
Pair Programming MythbustersPair Programming Mythbusters
Pair Programming Mythbusters
 
Shoeism - Frau im Glück
Shoeism - Frau im GlückShoeism - Frau im Glück
Shoeism - Frau im Glück
 
Bessere Software schneller liefern
Bessere Software schneller liefernBessere Software schneller liefern
Bessere Software schneller liefern
 
Von 0 auf 100 in 2 Sprints
Von 0 auf 100 in 2 SprintsVon 0 auf 100 in 2 Sprints
Von 0 auf 100 in 2 Sprints
 
Piwik anpassen und skalieren
Piwik anpassen und skalierenPiwik anpassen und skalieren
Piwik anpassen und skalieren
 
Agilitaet im E-Commerce - E-Commerce Breakfast
Agilitaet im E-Commerce - E-Commerce BreakfastAgilitaet im E-Commerce - E-Commerce Breakfast
Agilitaet im E-Commerce - E-Commerce Breakfast
 

Último

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Último (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"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...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"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
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

Javascript Testing Guide

  • 1. Javascript Testing Sebastian Springer I 10. Oktober 2011 © Mayflower GmbH 2010
  • 2. That's me I Diplom-Informatiker (FH) I Zend Certified Developer I Certified Oracle MySQL Developer I Scrum Master HI! MY NAME IS Sebastian Springer Mayflower GmbH I 2
  • 4. Agenda I Warum Testing? I Unittests I Integrationtests I Automatisierung ©SPH Mayflower GmbH I 4
  • 5. Warum Testing? ©姒儿喵喵 Mayflower GmbH I 5
  • 6. Warum Testing? I Sicherheit I Refactoring I Continuous Integration I Dokumentation Mayflower GmbH I 6
  • 7. Testing – Voraussetzungen ©姒儿喵喵 Mayflower GmbH I 7
  • 8. Testing – Voraussetzungen I Keine Hindernisse I Know-how I Testbarer Code Mayflower GmbH I 8
  • 9. Und warum Javascript? ©姒儿喵喵 Mayflower GmbH I 9
  • 10. Und warum Javascript? I Wachsende Bedeutung I User Experience I Mehr Logik I Mehr LoC ·Applikation vor 4 Jahren: ca. 3% Javascript ·Aktuelle Applikation: ca. 43% Javascript Mayflower GmbH I 10
  • 11. Unittests Mayflower GmbH I 11
  • 12. Unittest Frameworks © BM5k Mayflower GmbH I 12
  • 13. Unittests – Frameworks Nodeunit JSUnit UnitTesting QUnit TestCase jsUnitTest J3Unit D.O.H. YUI Test Mayflower GmbH I 13
  • 14. Unittests – Frameworks Nodeunit JSUnit UnitTesting QUnit TestCase jsUnitTest J3Unit D.O.H. YUI Test Mayflower GmbH I 14
  • 15. Unittests – QUnit <html> <head> <script src="scripts/library/jquery.js"></script> <script src="scripts/library/underscore.js"></script> <script src="scripts/library/backbone.js"></script> <script src="scripts/library/require.js"></script> <link rel="stylesheet" type="text/css" href="/style/style.css" /> <link rel="stylesheet" type="text/css" href="/style/qunit.css" /> <script src="/scripts/library/qunit.js"></script> Mayflower GmbH I 15
  • 16. Unittests – QUnit <script> require(['/scripts/application/models/ggt.js'], function(gcdClass) { var gcd = new gcdClass(); module('Greatest Common Divisor'); test("Check GCD Success, exact match", 1, function() {...}); test("Check GCD Success, no match", 1, function() {...}); test("Check GCD with Zero", 0, function() {...}); test("This should Fail", function() {...}); }); </script> Mayflower GmbH I 16
  • 17. Unittests – QUnit </head> <body> <h1 id="qunit-header">QUnit example</h1> <h2 id="qunit-banner"></h2> <div id="qunit-testrunner-toolbar"></div> <h2 id="qunit-userAgent"></h2> <ol id="qunit-tests"></ol> <div id="qunit-fixture">test markup, will be hidden</div> </body> </html> Mayflower GmbH I 17
  • 18. Unittests – QUnit Mayflower GmbH I 18
  • 19. Unittests – QUnit Asserts I ok(state, msg) I equal(actual, expected, msg) I deepEqual(actual, expected, msg) I strictEqual(actual, expected, msg) I raises(block, expected, msg) I not...(..., msg) ·notEqual(actual, expected, msg) Mayflower GmbH I 19
  • 20. Merkmale von Unittests Mayflower GmbH I 20
  • 21. Unittests – Isoliert I Isoliert Mayflower GmbH I 21
  • 22. Unittests – Isoliert function doALotOfAjaxMagicAndTakeACallback(cb) { $.ajax({ type: 'POST', dataType: 'json', data: '{}', contentType: 'application/json', url: 'my/backend', success: function(res) { var result = null; {...} return result; } }); } Mayflower GmbH I 22
  • 23. Unittests – Isoliert test("Test my ajax magic", function() { stop(); doALotOfAjaxMagicAndTakeACallback( function(result) { equals(result, "It's magic"); start(); } ); }); Mayflower GmbH I 23
  • 24. Unittests – Sinon.js I Test Spies I Stubs I Mocks I Fake Timers I Fake XHR und Server Mayflower GmbH I 24
  • 25. Unittests – Positiv/Negativ testing I Isoliert I Positiv/Negativ testing Mayflower GmbH I 25
  • 26. Unittests – Positiv/Negativ testing test("Check GCD", 1, function() { equal(3, gcd.calculate(15, 9)); }); Mayflower GmbH I 26
  • 27. Unittests – Positiv/Negativ testing test("Check GCD Success, exact match", 1, function() { equal(2, gcd.calculate(4, 2)); }); test("Check GCD Success, no match", 1, function() { equal(3, gcd.calculate(15, 9)); }); test("Check GCD Success with Zero", 2, function() { equal(4, gcd.calculate(0, 4)); equal(4, gcd.calculate(4, 0)); }); test("Check GCD Failure", 1, function() { equal(false, gcd.calculate('a', 'b')); }); Mayflower GmbH I 27
  • 28. Unittests – Häufige Ausführung I Isoliert I Positiv/Negativ testing I Häufige Ausführung Mayflower GmbH I 28
  • 29. Unittests – Häufige Ausführung Mayflower GmbH I 29
  • 30. Unittests – Blackbox testing I Isoliert I Positiv/Negativ testing I Häufige Ausführung I Blackbox testing – Input/Output Mayflower GmbH I 30
  • 31. Unittests – Blackbox testing /** * This method calculates the greatest common divisor * and returns the result * * @param m integer * @param n integer * * @return mixed integer result, false if invalid params */ calculate: function (m, n) { if (typeof m != 'number' || typeof n != 'number') { return false; } if (n == 0) { return m; } else if (m == 0) { return n; } else { return this.calculate(n, m % n); } } Mayflower GmbH I 31
  • 32. Unittests – Blackbox testing /** * This method calculates the greatest common divisor * and returns the result * * @param m integer * @param n integer * * @return mixed integer result, false if invalid params */ calculate: function (m, n) {...} Mayflower GmbH I 32
  • 33. Unittests – Test First I Isoliert I Positiv/Negativ testing I Häufige Ausführung I Blackbox testing – Input/Output I Test First/Test Parallel Mayflower GmbH I 33
  • 34. Unittests – Test First calculate: function (m, n) { if (typeof m != 'number' || typeof n != 'number') { return false; } if (n == 0) { return m; } else if (m == 0) { return n; } else { return this.calculate(n, m % n); } } test(“Check GDC“, function() { // @TODO write testlogic }); Mayflower GmbH I 34
  • 35. Unittests – Test First /** * This method calculates the greatest common divisor * and returns the result * * @param m integer * @param n integer * * @return mixed integer result, false if invalid params */ calculate: function (m, n) { return 2; } test(“Check GDC Success, exact match“, function() { equal(2, gcd.calculate(4, 2)); }); Mayflower GmbH I 35
  • 36. Testbarer Code Mayflower GmbH I 36
  • 37. Unittests – Voraussetzung: testbarer Code I Unabhängiger Code I Überschaubare Komplexität I Dependency Injection Mayflower GmbH I 37
  • 38. Organisation Mayflower GmbH I 38
  • 39. Unittests – Organisation I module() I test() Mayflower GmbH I 39
  • 40. Integrationtests Mayflower GmbH I 40
  • 41. Organisation © Potatojunkie Mayflower GmbH I 41
  • 42. Integrationtests – Selenium IDE Mayflower GmbH I 42
  • 43. Integrationtests – Häufig verwendete Kommandos I waitFor... ·z.B. waitForElementPresent I verify... ·z.B. verifyTextPresent I click I type I ... Mayflower GmbH I 43
  • 44. Locators Mayflower GmbH I 44
  • 45. Integrationtests – Selenium IDE Mayflower GmbH I 45
  • 46. Integrationtests – Locators I identifier=username I id=password I name=username I dom=document.forms[0] I xpath=//form[@id='loginForm']/div[1]/input[1] I link=myLinkText I css=div#loginBox Mayflower GmbH I 46
  • 47. Integrationtests – Variablen und Testsuites Mayflower GmbH I 47
  • 48. Selenium Stabilität? © andyarthur Mayflower GmbH I 48
  • 49. Automatisierung Mayflower GmbH I 49
  • 50. Automatisierung Mayflower GmbH I 50
  • 51. Automatisierung SVN Commit Jenkins CI Selenium QUnit Mayflower GmbH I 51
  • 52. Automatisierung – Selenium phpunit selenseDirectory Selenium RC/grid Selenium RC Browser Browser Browser Browser Jenkins Mayflower GmbH I 52
  • 53. Automatisierung – QUnit QUnit jsTestDriver Browser Browser Browser Browser Jenkins Mayflower GmbH I 53
  • 54. Fragen? © br1dotcom Mayflower GmbH I 54
  • 55. Vielen Dank für Ihre Aufmerksamkeit! Kontakt Sebastian Springer sebastian.springer@mayflower.de +49 89 242054 1120 Mayflower GmbH Mannhardtstrasse 6 80538 München 14.10.2011 Mayflower GmbH 55