SlideShare a Scribd company logo
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

More Related Content

Similar to Javascript Ttesting

JMockit
JMockitJMockit
JMockit
Angad Rajput
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
Ying Zhang
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
JWORKS powered by Ordina
 
Upstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testingUpstate CSCI 540 Unit testing
Upstate CSCI 540 Unit testing
DanWooster1
 
Никита Галкин "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 Galkin
Sigma Software
 
One-Click Deployment with Jenkins
One-Click Deployment with JenkinsOne-Click Deployment with Jenkins
One-Click Deployment with Jenkins
Mayflower GmbH
 
31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf31b - JUnit and Mockito.pdf
31b - JUnit and Mockito.pdf
gauravavam
 
Case Studies in Terrible Testing
Case Studies in Terrible TestingCase Studies in Terrible Testing
Case Studies in Terrible Testing
Todd Gardner
 
Google mock training
Google mock trainingGoogle mock training
Google mock training
Thierry Gayet
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in Java
Michael Fons
 
Junit
JunitJunit
Unit Test Fun
Unit Test FunUnit Test Fun
Unit Test Fun
Mayflower GmbH
 
DevOps for PHP
DevOps for PHPDevOps for PHP
DevOps for PHP
Mayflower GmbH
 
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
Salvador 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 Synchronization
cscarcas
 
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
Ravikiran J
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
vijay974055
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
karinaabyys
 
chapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio pptchapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio ppt
Abdikani34
 

Similar to Javascript Ttesting (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
 
chapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio pptchapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio ppt
 

More from 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
 
Why and what is go
Why and what is goWhy and what is go
Why and what is go
Mayflower GmbH
 
Agile Anti-Patterns
Agile Anti-PatternsAgile Anti-Patterns
Agile Anti-Patterns
Mayflower GmbH
 
JavaScript Days 2015: Security
JavaScript Days 2015: SecurityJavaScript Days 2015: Security
JavaScript Days 2015: Security
Mayflower GmbH
 
Vom Entwickler zur Führungskraft
Vom Entwickler zur FührungskraftVom Entwickler zur Führungskraft
Vom Entwickler zur Führungskraft
Mayflower GmbH
 
Produktive teams
Produktive teamsProduktive teams
Produktive teams
Mayflower 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 Client
Mayflower GmbH
 
Plugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debuggingPlugging holes — javascript memory leak debugging
Plugging holes — javascript memory leak debugging
Mayflower GmbH
 
Usability im web
Usability im webUsability im web
Usability im web
Mayflower GmbH
 
Rewrites überleben
Rewrites überlebenRewrites überleben
Rewrites überleben
Mayflower GmbH
 
JavaScript Security
JavaScript SecurityJavaScript Security
JavaScript Security
Mayflower 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
 
Responsive Webdesign
Responsive WebdesignResponsive Webdesign
Responsive Webdesign
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 Alloy
Mayflower GmbH
 
Pair Programming Mythbusters
Pair Programming MythbustersPair Programming Mythbusters
Pair Programming Mythbusters
Mayflower GmbH
 
Shoeism - Frau im Glück
Shoeism - Frau im GlückShoeism - Frau im Glück
Shoeism - Frau im Glück
Mayflower GmbH
 
Bessere Software schneller liefern
Bessere Software schneller liefernBessere Software schneller liefern
Bessere Software schneller liefern
Mayflower 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 Sprints
Mayflower GmbH
 
Piwik anpassen und skalieren
Piwik anpassen und skalierenPiwik anpassen und skalieren
Piwik anpassen und skalieren
Mayflower 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 Breakfast
Mayflower GmbH
 

More from 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
 

Recently uploaded

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 

Recently uploaded (20)

Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 

Javascript Ttesting

  • 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