SlideShare uma empresa Scribd logo
1 de 67
Testing Ext JS &
 Sencha Touch


              2012 Mats Bryntse
              @bryntum
Contents

• Why test your JavaScript?

• Testing Methodologies

• Introducing Siesta

• Writing testable JS

• Automating tests
About me
var me = {
   name        : ”Mats Bryntse”,
   age         : 35+,
   lives       : ”Helsingborg, Sweden”,
   does        : ”Runs Bryntum”,
   site        : ”www.bryntum.com”,
   twitter     : ”@bryntum”
};
What we do

Ext JS/ST Components


                       Siesta (JS Test Tool)
First, a quick raise of
        hands:

  How many of you...
How many of you...


• have a frontend test suite?

• have frontend test suite as part of your CI?

• run your test suite in all major browsers?

• have zero or fewer frontend tests for your app?
Why test your
JavaScript?
A typical web app...



                     Interwebs



http://www.app.com
The backend


         • Single controlled platform

         • Simple to test and refactor

         • Good IDEs and tools
PHP
    C#
 Java
The frontend
• Multiple platforms & versions
  (Mac, Windows XP/Vista/7/8, Linux...)


• Multiple browser versions

• Hard to refactor

• JavaScript support in IDEs is
  still !== awesome
Conclusion


Too easy to #FAIL as a frontend developer

Testing helps you keep fails to a minimum.
But...

”... my code is bug free”

”...testing takes time away from adding new
features (+ new bugs)”

”...it’s QA’s job to test”

”... it’s boring and I’ll quit my job”
A good investment

• Writing tests === investment in your code

• Takes time

• Will pay you back, though not instantly
Scenario:
A nasty bug was found

      3 options
[panic]
[patch it]
[proper fix]
A test suite...
=> confidence in your code

=> serves as extra documentation

=> easier refactoring

=> bugs happen once, easier to find

=======> quality of sleep
Code handover

• Test cases are really useful when handing over
  responsibility for a JS module

• Developer Bob quits his job. New guy gets
  responsibility of his JS code.

• How will new guy know what parts of the
  codebase is safe to change & refactor?
New guy studies codebase
 application.js

 /**
  * When I wrote this, only God and I understood what I was doing
  * Now, God only knows
  **/

 /* I am not sure if we need this, but too scared to delete. */

 // drunk, fix later

 // This is my last day...
Code handover

New guy, scared
Code handover

• Without test suite, will new guy feel good
  about making major changes?

• Only minor cosmetic changes on the surface.

• System accumulates cruft over time.

• Sounds familiar?
JS Testing
Methodologies
Unit testing

Integration testing

Functional testing
Unit testing


• Testing the API of a single isolated ’unit’

• Typically pure JS, non UI / DOM
    •   verify set/get method of a Model
    •   verify date manipulation logic


• Many tools available
Unit testing


• Siesta

• Jasmine

• QUnit (jQuery)

• Google js-test (V8)
Integration testing


• Testing integration between units.

• E.g. verify cell editing plugin works in
  GridPanel
Functional Web testing


• UI testing of a component or an application
  as a whole.

• Send commands to the web page and
  evaluate result.

• ’click button’, ’type into login field’, ...
Functional Web testing


• Siesta

• Selenium

• JsTestDriver
Interacting with the DOM

 Approaches to faking user input

  • Synthetic events (JavaScript)

  • Native events (via Java Applet)
Synthetic events
+ Supported in all major browsers
+ Compatible with mobile
+ Don’t rely on native event queue
     Tests can be run in parallell.




- Browsers don’t ”trust” synthetic events
 -   Enter key on a focused link
 -   Tab between input fields, etc...
- X-browser differences
 DOM Events, Key events, key codes (http://unixpapa.com)
Native events

+ Java applets are supported in desktop
browsers
+ As close to a ’real’ user as possible


- Won’t work on iOS, Android.
- No parallell tests since native event queue
is used.
What is Siesta?

• Unit testing and DOM testing tool

• Optimized for Ext JS & Sencha Touch
   - also supports jQuery, NodeJS, or any JS


• Simple syntax, Extensible

• Automate using PhantomJS & Selenium.
Siesta Browser Harness
Siesta Browser Harness

• A UI for Siesta, view DOM, inspect assertions

• Define a tree of tests, in logical groups

• Global settings for the test suite
        autoCheckGlobals, preload, testClass
A Siesta Test

• is pure JavaScript, no magic.

StartTest(function(t) {

      $('body').html('JQuery was here');

      t.contentLike(document.body,
                   'JQuery was here',
                   'Found correct text in DOM');
});
A Siesta Test

• is completely isolated in its own iframe
   (no teardown, cleanup required)
A Siesta Test

• can be extended with your own custom
  assertions and helper methods

StartTest(function(myTest) {
    var app = myTest.startApplication();

      myTest.performLogin(app);
      myTest.isLoggedIn(app, ’Logged in ok’);
      myTest.is(app.nbrUsers, 1, ’Found 1 user’);
});
Lifecycle of a UI test

Setup      create grid, load stores

Wait       for store to load, grid rows to render

Simulate   click button, type into textbox

Verify     isEqual(a, b)
Setup



var userGrid = new My.UserGrid({ … });

userGrid.render(Ext.getBody());
Wait

t.waitForRowsVisible(userGrid, function(){
    // Do something
});


t.waitForComponentQuery(“formpanel > textfield”);


t.waitForCompositeQuery(“grid => .x-grid-row”);
Simulate

// A list of actions to simulate
t.chain(
     {
           desc            : 'Should click trigger field',
           action          : 'click',
           target          : 'testgrid triggerfield'
     },
     {
           desc            : 'Should type into filter field',
           action          : 'type',
           target          : 'testgrid triggerfield',
           text            : 'FOO'
     }, ...
);
Verify

t.is(userStore.getCount(), 5, ”5 users found”);


t.willFireNTimes(store, 2, ”write”);


t.hasCls(grid.getEl(), ”myClass”, ”Found CSS”);


t.hasSize(myWindow, 300, 300,   ”Window size ok”);
DEMO
Sencha Touch support




Simulate tap, doubleTap, swipe, longPress, etc...
Siesta.next

• Benchmarking

• Code coverage

• Multi-browser, multi-device testing
• Crowd sourced test case tool “Code Cowboy”

• Your suggestion?
Headless testing


• Headless browsers are great, fast

• Command line, easy to integrate with IDEs

• PhantomJS, GUI-less WebKit browser
Phantom JS
Created by Ariya Hidayat (Sencha Inc.)

Fast headless testing

Site scraping

SVG rendering, PDF/PNG output

Supports CoffeeScript
Headless browsers

+ Run tests on command line
+ Faster
+ Automation
+ Doesn’t require an actual browser


- Not 100% accurate, but close.
Writing testable JS
Some ground rules

• Keep your JavaScript in JS files

• Never put JavaScript in your HTML
  page/tags

• Keep code organized in logical manageable
  files. Decide on some max nbr of lines/file.
No no no
Testable MVC code

• Fat model, skinny view

• Don’t pollute your views with business logic

• Testing pure JS is a lot easier than testing
  DOM-dependent JS

• Promotes reuse of your code
Mixing view and logic

Ext.define('UserForm', {
    extend: 'Ext.FormPanel',
    width: 400,
    height: 400,

      // Returns true if User is valid
      isValid: function (userModel) {
          return userModel.name.length > 4 &&
                 userModel.password.length > 8;
      }
});
Better

Ext.define('UserModel', {
    extend: 'Ext.data.Model ',
    name : '',
    password : '',

      isValid : function () {
             return this.name.length > 4 &&
                    this.password.length > 8;
      }
});
Refactored view

Ext.define('UserForm', {
    extend: 'Ext.FormPanel',
    width: 400,
    height: 400,

      // Returns true if User is valid
      isValid: function () {
          return this.model.isValid();
      }
});
Avoid private code


• Avoid overuse of private functions in
  closures

• If your code cannot be accessed it cannot
  be tested
Testing Ajax

• Try to avoid involving your database.

• Use either static JS files with mock data
  (async, slower)

• Or Mock the entire Ajax call (sync, faster)
   Sinon.js, Jasmine-ajax etc.
Automation &
Continuous Integration
Continuous Integration

• Once you have decided on your testing
  toolset, integrate it with your CI.

• Automatically run test suite on pre-commit
  or post-commit

• Nightly builds, full test suite execution,
  reporting via email etc.
CI Tools

• Jenkins

• TeamCity

• Cruise Control

• Test Swarm
JS Code Coverage

• JsCoverage
   Seems abandoned



• ScriptCover
   Google Chrome Plugin



• JsTestDriver
   Add-in module for coverage



• JesCov
   Rhino, Jasmine
Resources - Yahoo
http://screen.yahoo.com/
Resources - GTAC
”Without unit tests, you’re
         not refactoring. You’re just
         changing shit.”



Hamlet D’Arcy
Thanks for listening!


     Questions?



                  2012 Mats Bryntse
                  @bryntum

Mais conteúdo relacionado

Mais procurados

Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to ProtractorJie-Wei Wu
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksAddy Osmani
 
Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Deutsche Post
 
UI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected JourneyUI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected JourneyOren Farhi
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015Matt Raible
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Hazem Saleh
 
An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorCubet Techno Labs
 
Test your Javascript! v1.1
Test your Javascript! v1.1Test your Javascript! v1.1
Test your Javascript! v1.1Eric Wendelin
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Andrew Eisenberg
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and RubyYnon Perek
 
Automation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and BeyondAutomation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and BeyondAlan Richardson
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Ran Mizrahi
 
Automated Testing With Watir
Automated Testing With WatirAutomated Testing With Watir
Automated Testing With WatirTimothy Fisher
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptRohan Chandane
 
Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using RubyKumari Warsha Goel
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Jay Friendly
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF SummitOrtus Solutions, Corp
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript TestingRan Mizrahi
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJSPeter Drinnan
 

Mais procurados (20)

Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
 
Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)
 
UI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected JourneyUI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected Journey
 
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
#NoXML: Eliminating XML in Spring Projects - SpringOne 2GX 2015
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
An Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using ProtractorAn Introduction to AngularJS End to End Testing using Protractor
An Introduction to AngularJS End to End Testing using Protractor
 
Test your Javascript! v1.1
Test your Javascript! v1.1Test your Javascript! v1.1
Test your Javascript! v1.1
 
Marcin Wasilczyk - Page objects with selenium
Marcin Wasilczyk - Page objects with seleniumMarcin Wasilczyk - Page objects with selenium
Marcin Wasilczyk - Page objects with selenium
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
 
Automation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and BeyondAutomation Abstraction Layers: Page Objects and Beyond
Automation Abstraction Layers: Page Objects and Beyond
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
 
Automated Testing With Watir
Automated Testing With WatirAutomated Testing With Watir
Automated Testing With Watir
 
Sencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScriptSencha / ExtJS : Object Oriented JavaScript
Sencha / ExtJS : Object Oriented JavaScript
 
Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using Ruby
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript Testing
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 

Destaque

Selenium. Stas Kuzminov
Selenium. Stas KuzminovSelenium. Stas Kuzminov
Selenium. Stas KuzminovADCI Solutions
 
White-box Unit Test Generation with Microsoft IntelliTest
White-box Unit Test Generation with Microsoft IntelliTestWhite-box Unit Test Generation with Microsoft IntelliTest
White-box Unit Test Generation with Microsoft IntelliTestDávid Honfi
 
Selenide –  лаконичные тесты на Selenium 2 WebDriver + Java bindings
Selenide –  лаконичные тесты на Selenium 2 WebDriver + Java bindingsSelenide –  лаконичные тесты на Selenium 2 WebDriver + Java bindings
Selenide –  лаконичные тесты на Selenium 2 WebDriver + Java bindingsCOMAQA.BY
 
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...Sencha
 
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...Sencha
 

Destaque (9)

ExtJS WebDriver
ExtJS WebDriverExtJS WebDriver
ExtJS WebDriver
 
Selenium. Stas Kuzminov
Selenium. Stas KuzminovSelenium. Stas Kuzminov
Selenium. Stas Kuzminov
 
White-box Unit Test Generation with Microsoft IntelliTest
White-box Unit Test Generation with Microsoft IntelliTestWhite-box Unit Test Generation with Microsoft IntelliTest
White-box Unit Test Generation with Microsoft IntelliTest
 
Selenide –  лаконичные тесты на Selenium 2 WebDriver + Java bindings
Selenide –  лаконичные тесты на Selenium 2 WebDriver + Java bindingsSelenide –  лаконичные тесты на Selenium 2 WebDriver + Java bindings
Selenide –  лаконичные тесты на Selenium 2 WebDriver + Java bindings
 
test generation
test generationtest generation
test generation
 
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
SenchaCon 2016: How Sencha Test Helps Automate Functional Testing of Ext JS M...
 
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
SenchaCon 2016: The Changing Landscape of JavaScript Testing - Joel Watson an...
 
Basic Selenium Training
Basic Selenium TrainingBasic Selenium Training
Basic Selenium Training
 
Brazil Startup Report
Brazil Startup ReportBrazil Startup Report
Brazil Startup Report
 

Semelhante a Testing Ext JS and Sencha Touch

Java script unit testing
Java script unit testingJava script unit testing
Java script unit testingMats Bryntse
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETBen Hall
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014Alex Kavanagh
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsLuís Bastião Silva
 
UI Testing Automation
UI Testing AutomationUI Testing Automation
UI Testing AutomationAgileEngine
 
Node.js Development Workflow Automation with Grunt.js
Node.js Development Workflow Automation with Grunt.jsNode.js Development Workflow Automation with Grunt.js
Node.js Development Workflow Automation with Grunt.jskiyanwang
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - Ortus Solutions, Corp
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION APIGavin Pickin
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!Ortus Solutions, Corp
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testingdrewz lin
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
Building Rich Internet Applications with Ext JS
Building Rich Internet Applications  with Ext JSBuilding Rich Internet Applications  with Ext JS
Building Rich Internet Applications with Ext JSMats Bryntse
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkSusannSgorzaly
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWHolger Grosse-Plankermann
 

Semelhante a Testing Ext JS and Sencha Touch (20)

Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
 
UI Testing Automation
UI Testing AutomationUI Testing Automation
UI Testing Automation
 
Node.js Development Workflow Automation with Grunt.js
Node.js Development Workflow Automation with Grunt.jsNode.js Development Workflow Automation with Grunt.js
Node.js Development Workflow Automation with Grunt.js
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API - 3 WAYS TO TEST YOUR COLDFUSION API -
3 WAYS TO TEST YOUR COLDFUSION API -
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Ext JS Introduction
Ext JS IntroductionExt JS Introduction
Ext JS Introduction
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Building Rich Internet Applications with Ext JS
Building Rich Internet Applications  with Ext JSBuilding Rich Internet Applications  with Ext JS
Building Rich Internet Applications with Ext JS
 
Testing mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP frameworkTesting mit Codeception: Full-stack testing PHP framework
Testing mit Codeception: Full-stack testing PHP framework
 
Selenium
SeleniumSelenium
Selenium
 
Building XWiki
Building XWikiBuilding XWiki
Building XWiki
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 
Gallio Crafting A Toolchain
Gallio Crafting A ToolchainGallio Crafting A Toolchain
Gallio Crafting A Toolchain
 

Último

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
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Último (20)

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
 
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
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Testing Ext JS and Sencha Touch

  • 1. Testing Ext JS & Sencha Touch 2012 Mats Bryntse @bryntum
  • 2. Contents • Why test your JavaScript? • Testing Methodologies • Introducing Siesta • Writing testable JS • Automating tests
  • 3. About me var me = { name : ”Mats Bryntse”, age : 35+, lives : ”Helsingborg, Sweden”, does : ”Runs Bryntum”, site : ”www.bryntum.com”, twitter : ”@bryntum” };
  • 4. What we do Ext JS/ST Components Siesta (JS Test Tool)
  • 5. First, a quick raise of hands: How many of you...
  • 6. How many of you... • have a frontend test suite? • have frontend test suite as part of your CI? • run your test suite in all major browsers? • have zero or fewer frontend tests for your app?
  • 8. A typical web app... Interwebs http://www.app.com
  • 9. The backend • Single controlled platform • Simple to test and refactor • Good IDEs and tools PHP C# Java
  • 10. The frontend • Multiple platforms & versions (Mac, Windows XP/Vista/7/8, Linux...) • Multiple browser versions • Hard to refactor • JavaScript support in IDEs is still !== awesome
  • 11. Conclusion Too easy to #FAIL as a frontend developer Testing helps you keep fails to a minimum.
  • 12. But... ”... my code is bug free” ”...testing takes time away from adding new features (+ new bugs)” ”...it’s QA’s job to test” ”... it’s boring and I’ll quit my job”
  • 13. A good investment • Writing tests === investment in your code • Takes time • Will pay you back, though not instantly
  • 14. Scenario: A nasty bug was found 3 options
  • 18. A test suite... => confidence in your code => serves as extra documentation => easier refactoring => bugs happen once, easier to find =======> quality of sleep
  • 19. Code handover • Test cases are really useful when handing over responsibility for a JS module • Developer Bob quits his job. New guy gets responsibility of his JS code. • How will new guy know what parts of the codebase is safe to change & refactor?
  • 20. New guy studies codebase application.js /** * When I wrote this, only God and I understood what I was doing * Now, God only knows **/ /* I am not sure if we need this, but too scared to delete. */ // drunk, fix later // This is my last day...
  • 22. Code handover • Without test suite, will new guy feel good about making major changes? • Only minor cosmetic changes on the surface. • System accumulates cruft over time. • Sounds familiar?
  • 25. Unit testing • Testing the API of a single isolated ’unit’ • Typically pure JS, non UI / DOM • verify set/get method of a Model • verify date manipulation logic • Many tools available
  • 26. Unit testing • Siesta • Jasmine • QUnit (jQuery) • Google js-test (V8)
  • 27. Integration testing • Testing integration between units. • E.g. verify cell editing plugin works in GridPanel
  • 28. Functional Web testing • UI testing of a component or an application as a whole. • Send commands to the web page and evaluate result. • ’click button’, ’type into login field’, ...
  • 29. Functional Web testing • Siesta • Selenium • JsTestDriver
  • 30. Interacting with the DOM Approaches to faking user input • Synthetic events (JavaScript) • Native events (via Java Applet)
  • 31. Synthetic events + Supported in all major browsers + Compatible with mobile + Don’t rely on native event queue Tests can be run in parallell. - Browsers don’t ”trust” synthetic events - Enter key on a focused link - Tab between input fields, etc... - X-browser differences DOM Events, Key events, key codes (http://unixpapa.com)
  • 32. Native events + Java applets are supported in desktop browsers + As close to a ’real’ user as possible - Won’t work on iOS, Android. - No parallell tests since native event queue is used.
  • 33.
  • 34. What is Siesta? • Unit testing and DOM testing tool • Optimized for Ext JS & Sencha Touch - also supports jQuery, NodeJS, or any JS • Simple syntax, Extensible • Automate using PhantomJS & Selenium.
  • 36. Siesta Browser Harness • A UI for Siesta, view DOM, inspect assertions • Define a tree of tests, in logical groups • Global settings for the test suite autoCheckGlobals, preload, testClass
  • 37. A Siesta Test • is pure JavaScript, no magic. StartTest(function(t) { $('body').html('JQuery was here'); t.contentLike(document.body, 'JQuery was here', 'Found correct text in DOM'); });
  • 38. A Siesta Test • is completely isolated in its own iframe (no teardown, cleanup required)
  • 39. A Siesta Test • can be extended with your own custom assertions and helper methods StartTest(function(myTest) { var app = myTest.startApplication(); myTest.performLogin(app); myTest.isLoggedIn(app, ’Logged in ok’); myTest.is(app.nbrUsers, 1, ’Found 1 user’); });
  • 40. Lifecycle of a UI test Setup create grid, load stores Wait for store to load, grid rows to render Simulate click button, type into textbox Verify isEqual(a, b)
  • 41. Setup var userGrid = new My.UserGrid({ … }); userGrid.render(Ext.getBody());
  • 42. Wait t.waitForRowsVisible(userGrid, function(){ // Do something }); t.waitForComponentQuery(“formpanel > textfield”); t.waitForCompositeQuery(“grid => .x-grid-row”);
  • 43. Simulate // A list of actions to simulate t.chain( { desc : 'Should click trigger field', action : 'click', target : 'testgrid triggerfield' }, { desc : 'Should type into filter field', action : 'type', target : 'testgrid triggerfield', text : 'FOO' }, ... );
  • 44. Verify t.is(userStore.getCount(), 5, ”5 users found”); t.willFireNTimes(store, 2, ”write”); t.hasCls(grid.getEl(), ”myClass”, ”Found CSS”); t.hasSize(myWindow, 300, 300, ”Window size ok”);
  • 45. DEMO
  • 46. Sencha Touch support Simulate tap, doubleTap, swipe, longPress, etc...
  • 47. Siesta.next • Benchmarking • Code coverage • Multi-browser, multi-device testing • Crowd sourced test case tool “Code Cowboy” • Your suggestion?
  • 48. Headless testing • Headless browsers are great, fast • Command line, easy to integrate with IDEs • PhantomJS, GUI-less WebKit browser
  • 49. Phantom JS Created by Ariya Hidayat (Sencha Inc.) Fast headless testing Site scraping SVG rendering, PDF/PNG output Supports CoffeeScript
  • 50. Headless browsers + Run tests on command line + Faster + Automation + Doesn’t require an actual browser - Not 100% accurate, but close.
  • 52. Some ground rules • Keep your JavaScript in JS files • Never put JavaScript in your HTML page/tags • Keep code organized in logical manageable files. Decide on some max nbr of lines/file.
  • 54. Testable MVC code • Fat model, skinny view • Don’t pollute your views with business logic • Testing pure JS is a lot easier than testing DOM-dependent JS • Promotes reuse of your code
  • 55. Mixing view and logic Ext.define('UserForm', { extend: 'Ext.FormPanel', width: 400, height: 400, // Returns true if User is valid isValid: function (userModel) { return userModel.name.length > 4 && userModel.password.length > 8; } });
  • 56. Better Ext.define('UserModel', { extend: 'Ext.data.Model ', name : '', password : '', isValid : function () { return this.name.length > 4 && this.password.length > 8; } });
  • 57. Refactored view Ext.define('UserForm', { extend: 'Ext.FormPanel', width: 400, height: 400, // Returns true if User is valid isValid: function () { return this.model.isValid(); } });
  • 58. Avoid private code • Avoid overuse of private functions in closures • If your code cannot be accessed it cannot be tested
  • 59. Testing Ajax • Try to avoid involving your database. • Use either static JS files with mock data (async, slower) • Or Mock the entire Ajax call (sync, faster) Sinon.js, Jasmine-ajax etc.
  • 61. Continuous Integration • Once you have decided on your testing toolset, integrate it with your CI. • Automatically run test suite on pre-commit or post-commit • Nightly builds, full test suite execution, reporting via email etc.
  • 62. CI Tools • Jenkins • TeamCity • Cruise Control • Test Swarm
  • 63. JS Code Coverage • JsCoverage Seems abandoned • ScriptCover Google Chrome Plugin • JsTestDriver Add-in module for coverage • JesCov Rhino, Jasmine
  • 66. ”Without unit tests, you’re not refactoring. You’re just changing shit.” Hamlet D’Arcy
  • 67. Thanks for listening! Questions? 2012 Mats Bryntse @bryntum