SlideShare a Scribd company logo
Reinforcing your Backbone.js app
                with tests
                Mark Roseboom
                  Crashlytics


1               CRASHLYTICS CONFIDENTIAL   © 2013. All rights reserved
Tests are for real engineers...

           I work on the front end,
              I don’t need tests.




3                 CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
Testing matters for front end

    ‣ Maintain structure and reliability
    ‣ Insulate from 3rd parties

    ‣ Minimize team development concerns

    ‣ Spot-check poorly written code




4                     CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
Lets break it down
            Unit       Integration                          Feature
                                                                Clear
             Fast         Env Specific
                                                              Definitions
    Pros




            Easy to          System                               User
            Debug         Interactions                          Focused




            Isolated                               Slow
    Cons




                                                  Hard to
                                                  Debug


5                      CRASHLYTICS CONFIDENTIAL             © 2012. All rights reserved
Unit tests for Backbone.js




6               CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
What is Jasmine?




7       CRASHLYTICS CONFIDENTIAL   ©2013. All rights reserved
Standalone unit testing library
          ‣   Suites - Describe behavior
          ‣   Specs - Assert expectations
          ‣   Matchers - Boolean Comparison
    describe 'test suite', ->

      it 'has a spec, with an expectation', -> expect(true).toBe true

      describe 'nested suite', ->

        it 'has many matchers', ->
          foo = bar : 'bar', baz : null
          expect(foo).not.toEqual 'qux'
          expect(foo.bar).toBeDefined()
          expect(foo.baz).toBeNull()




8                               CRASHLYTICS CONFIDENTIAL     © 2012. All rights reserved
Stubbing and mocking methods

    describe 'spies', ->
      it 'can stub existing object methods', ->
        foo = bar : (value) -> console.log value
        spyOn foo, 'bar'
        foo.bar 'a value'
        expect(foo.bar).toHaveBeenCalled()

      describe 'mocking new methods', ->

        it 'can create new spies', ->
          spy = jasmine.createSpy 'spy'
          spy 'an argument'
          expect(spy).toHaveBeenCalledWith 'an argument'

        it 'can create a mock with multiple spies', ->
          spyObj = jasmine.createSpyObj 'spyObj', ['method']
          spyObj.method()
          expect(spyObj.method).toHaveBeenCalled()




9                             CRASHLYTICS CONFIDENTIAL     © 2012. All rights reserved
Controlling spy behavior

     describe 'spy behavior', ->
      beforeEach -> @foo = bar : (value) -> value
      beforeEach -> spyOn @foo, 'bar'

      it 'can delegate the actual implementation', ->
        @foo.bar.andCallThrough()
        result = @foo.bar 'a value'
        expect(@foo.bar).toHaveBeenCalled()
        expect(result).toEqual 'a value'

      it 'can return a specified value', ->
        @foo.bar.andReturn 'another value'
        result = @foo.bar 'a value'
        expect(result).toEqual 'another value'


      it 'can delegate to a callback', ->
        @foo.bar.andCallFake console.log
        @foo.bar 'a value'
        # console output: 'a value'




10                             CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
Tailoring Jasmine for Backbone.js




11                CRASHLYTICS CONFIDENTIAL   ©2013. All rights reserved
Jasmine-given

     describe 'spy behavior', ->
       beforeEach -> @foo = bar : (value) -> value
       beforeEach -> spyOn @foo, 'bar'

       it 'can delegate the actual implementation', ->
         @foo.bar.andCallThrough()
         result = @foo.bar 'a value'
         expect(@foo.bar).toHaveBeenCalled()
         expect(result).toEqual 'a value'
                                      Text




     describe 'spy behavior', ->

       Given -> @foo = bar : (value) -> value
       Given -> spyOn(@foo, 'bar').andCallThrough()
       When -> @result = @foo.bar 'a value'
       Then -> expect(@foo.bar).toHaveBeenCalled()
       Then -> expect(@result).toEqual 'a value'




12                                 CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
Jasmine-jQuery

     class Profile extends Backbone.View
       id : 'profile'

       showEmail : -> @$el.addClass 'show'




       describe 'showEmail', ->
         Given -> @view = new Profile()
         When -> @view.showEmail()
         Then -> expect(@view.$el.hasClass 'show').toBe true




       describe 'showEmail', ->
         Given -> @view = new Profile()
         When -> @view.showEmail()
         Then -> expect(@view.$el).hasClass 'show'




13                                CRASHLYTICS CONFIDENTIAL     © 2012. All rights reserved
Start testing your app




14          CRASHLYTICS CONFIDENTIAL   ©2013. All rights reserved
Backbone View - Todo MVC




15             CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
Backbone View - Todo MVC




16             CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
Backbone View - Todo MVC




17             CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
What’s next...




18      CRASHLYTICS CONFIDENTIAL   ©2013. All rights reserved
Bigger picture




         Feature and integration tests
           Continuous integration

19                 CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
Resources

     ‣   Jasmine - http://pivotal.github.com/jasmine/
     ‣   Jasmine-Given - https://github.com/searls/jasmine-given
     ‣   Jasmine-jQuery - https://github.com/velesin/jasmine-jquery
     ‣   Jasmine-Stealth - https://github.com/searls/jasmine-stealth




20                              CRASHLYTICS CONFIDENTIAL   © 2012. All rights reserved
Thank You
       (we’re hiring)
              Mark Roseboom
                Crashlytics




21      CRASHLYTICS CONFIDENTIAL   © 2013. All rights reserved

More Related Content

What's hot

Paying off technical debt with PHPSpec
Paying off technical debt with PHPSpecPaying off technical debt with PHPSpec
Paying off technical debt with PHPSpec
Lewis Wright
 
AngularJS Tips&Tricks
AngularJS Tips&TricksAngularJS Tips&Tricks
AngularJS Tips&Tricks
Petr Bela
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
jhoguet
 
Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHP
Marcello Duarte
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
Frank de Jonge
 
Solid principles
Solid principlesSolid principles
Solid principles
Declan Whelan
 
Proposed PHP function: is_literal()
Proposed PHP function: is_literal()Proposed PHP function: is_literal()
Proposed PHP function: is_literal()
Craig Francis
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
Dzmitry Ivashutsin
 
Things to consider for testable Code
Things to consider for testable CodeThings to consider for testable Code
Things to consider for testable Code
Frank Kleine
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
Roy Yu
 
Asp.net mvc internals & extensibility
Asp.net mvc internals & extensibilityAsp.net mvc internals & extensibility
Asp.net mvc internals & extensibility
Eyal Vardi
 
Čtvrtkon #53 - Štěpán Zikmund
Čtvrtkon #53 - Štěpán ZikmundČtvrtkon #53 - Štěpán Zikmund
Čtvrtkon #53 - Štěpán Zikmund
Péhápkaři
 
Factory Girl
Factory GirlFactory Girl
Factory Girl
Gabe Evans
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
tepsum
 
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
AMD & Require.js
AMD & Require.jsAMD & Require.js
AMD & Require.js
Eyal Vardi
 
Automated Refactoring With IntelliJ IDEA
Automated Refactoring With IntelliJ IDEA Automated Refactoring With IntelliJ IDEA
Automated Refactoring With IntelliJ IDEA
CodeOps Technologies LLP
 
Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching PatternDeadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
chibochibo
 

What's hot (19)

Paying off technical debt with PHPSpec
Paying off technical debt with PHPSpecPaying off technical debt with PHPSpec
Paying off technical debt with PHPSpec
 
AngularJS Tips&Tricks
AngularJS Tips&TricksAngularJS Tips&Tricks
AngularJS Tips&Tricks
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
 
Functional Structures in PHP
Functional Structures in PHPFunctional Structures in PHP
Functional Structures in PHP
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Proposed PHP function: is_literal()
Proposed PHP function: is_literal()Proposed PHP function: is_literal()
Proposed PHP function: is_literal()
 
ngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency InjectionngMess: AngularJS Dependency Injection
ngMess: AngularJS Dependency Injection
 
Things to consider for testable Code
Things to consider for testable CodeThings to consider for testable Code
Things to consider for testable Code
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
 
Asp.net mvc internals & extensibility
Asp.net mvc internals & extensibilityAsp.net mvc internals & extensibility
Asp.net mvc internals & extensibility
 
Download It
Download ItDownload It
Download It
 
Čtvrtkon #53 - Štěpán Zikmund
Čtvrtkon #53 - Štěpán ZikmundČtvrtkon #53 - Štěpán Zikmund
Čtvrtkon #53 - Štěpán Zikmund
 
Factory Girl
Factory GirlFactory Girl
Factory Girl
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
 
AMD & Require.js
AMD & Require.jsAMD & Require.js
AMD & Require.js
 
Automated Refactoring With IntelliJ IDEA
Automated Refactoring With IntelliJ IDEA Automated Refactoring With IntelliJ IDEA
Automated Refactoring With IntelliJ IDEA
 
Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching PatternDeadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
 

Similar to Backbone testing

Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
Daniel Spector
 
Security testing of YUI powered applications
Security testing of YUI powered applicationsSecurity testing of YUI powered applications
Security testing of YUI powered applications
dimisec
 
Java, Up to Date
Java, Up to DateJava, Up to Date
Java, Up to Date
輝 子安
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Paul King
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
Andrea Paciolla
 
Hybrid Applications
Hybrid ApplicationsHybrid Applications
Hybrid Applications
Andreas Enbohm
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
Gregor Woiwode
 
Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.js
Return on Intelligence
 
Java EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e MudançasJava EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e Mudanças
Bruno Borges
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
ranjanadeore1
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
dizabl
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQL
Lukas Eder
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
Mek Srunyu Stittri
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
Arun Gupta
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e bigAndy Peterson
 
Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...
Kevin Poorman
 
In The Future We All Use Symfony2
In The Future We All Use Symfony2In The Future We All Use Symfony2
In The Future We All Use Symfony2
Brent Shaffer
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 

Similar to Backbone testing (20)

Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
 
Security testing of YUI powered applications
Security testing of YUI powered applicationsSecurity testing of YUI powered applications
Security testing of YUI powered applications
 
Deep dive into Oracle ADF
Deep dive into Oracle ADFDeep dive into Oracle ADF
Deep dive into Oracle ADF
 
Java, Up to Date
Java, Up to DateJava, Up to Date
Java, Up to Date
 
Sightly_techInsight
Sightly_techInsightSightly_techInsight
Sightly_techInsight
 
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
Industrial Strength Groovy - Tools for the Professional Groovy Developer: Pau...
 
Javascript tdd byandreapaciolla
Javascript tdd byandreapaciollaJavascript tdd byandreapaciolla
Javascript tdd byandreapaciolla
 
Hybrid Applications
Hybrid ApplicationsHybrid Applications
Hybrid Applications
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.js
 
Java EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e MudançasJava EE 7 - Novidades e Mudanças
Java EE 7 - Novidades e Mudanças
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQL
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...Connecting with the enterprise - The how and why of connecting to Enterprise ...
Connecting with the enterprise - The how and why of connecting to Enterprise ...
 
In The Future We All Use Symfony2
In The Future We All Use Symfony2In The Future We All Use Symfony2
In The Future We All Use Symfony2
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 

Recently uploaded

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
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
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
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 !
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 

Backbone testing

  • 1. Reinforcing your Backbone.js app with tests Mark Roseboom Crashlytics 1 CRASHLYTICS CONFIDENTIAL © 2013. All rights reserved
  • 2.
  • 3. Tests are for real engineers... I work on the front end, I don’t need tests. 3 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 4. Testing matters for front end ‣ Maintain structure and reliability ‣ Insulate from 3rd parties ‣ Minimize team development concerns ‣ Spot-check poorly written code 4 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 5. Lets break it down Unit Integration Feature Clear Fast Env Specific Definitions Pros Easy to System User Debug Interactions Focused Isolated Slow Cons Hard to Debug 5 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 6. Unit tests for Backbone.js 6 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 7. What is Jasmine? 7 CRASHLYTICS CONFIDENTIAL ©2013. All rights reserved
  • 8. Standalone unit testing library ‣ Suites - Describe behavior ‣ Specs - Assert expectations ‣ Matchers - Boolean Comparison describe 'test suite', -> it 'has a spec, with an expectation', -> expect(true).toBe true describe 'nested suite', -> it 'has many matchers', -> foo = bar : 'bar', baz : null expect(foo).not.toEqual 'qux' expect(foo.bar).toBeDefined() expect(foo.baz).toBeNull() 8 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 9. Stubbing and mocking methods describe 'spies', -> it 'can stub existing object methods', -> foo = bar : (value) -> console.log value spyOn foo, 'bar' foo.bar 'a value' expect(foo.bar).toHaveBeenCalled() describe 'mocking new methods', -> it 'can create new spies', -> spy = jasmine.createSpy 'spy' spy 'an argument' expect(spy).toHaveBeenCalledWith 'an argument' it 'can create a mock with multiple spies', -> spyObj = jasmine.createSpyObj 'spyObj', ['method'] spyObj.method() expect(spyObj.method).toHaveBeenCalled() 9 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 10. Controlling spy behavior describe 'spy behavior', -> beforeEach -> @foo = bar : (value) -> value beforeEach -> spyOn @foo, 'bar' it 'can delegate the actual implementation', -> @foo.bar.andCallThrough() result = @foo.bar 'a value' expect(@foo.bar).toHaveBeenCalled() expect(result).toEqual 'a value' it 'can return a specified value', -> @foo.bar.andReturn 'another value' result = @foo.bar 'a value' expect(result).toEqual 'another value' it 'can delegate to a callback', -> @foo.bar.andCallFake console.log @foo.bar 'a value' # console output: 'a value' 10 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 11. Tailoring Jasmine for Backbone.js 11 CRASHLYTICS CONFIDENTIAL ©2013. All rights reserved
  • 12. Jasmine-given describe 'spy behavior', -> beforeEach -> @foo = bar : (value) -> value beforeEach -> spyOn @foo, 'bar' it 'can delegate the actual implementation', -> @foo.bar.andCallThrough() result = @foo.bar 'a value' expect(@foo.bar).toHaveBeenCalled() expect(result).toEqual 'a value' Text describe 'spy behavior', -> Given -> @foo = bar : (value) -> value Given -> spyOn(@foo, 'bar').andCallThrough() When -> @result = @foo.bar 'a value' Then -> expect(@foo.bar).toHaveBeenCalled() Then -> expect(@result).toEqual 'a value' 12 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 13. Jasmine-jQuery class Profile extends Backbone.View id : 'profile' showEmail : -> @$el.addClass 'show' describe 'showEmail', -> Given -> @view = new Profile() When -> @view.showEmail() Then -> expect(@view.$el.hasClass 'show').toBe true describe 'showEmail', -> Given -> @view = new Profile() When -> @view.showEmail() Then -> expect(@view.$el).hasClass 'show' 13 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 14. Start testing your app 14 CRASHLYTICS CONFIDENTIAL ©2013. All rights reserved
  • 15. Backbone View - Todo MVC 15 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 16. Backbone View - Todo MVC 16 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 17. Backbone View - Todo MVC 17 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 18. What’s next... 18 CRASHLYTICS CONFIDENTIAL ©2013. All rights reserved
  • 19. Bigger picture Feature and integration tests Continuous integration 19 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 20. Resources ‣ Jasmine - http://pivotal.github.com/jasmine/ ‣ Jasmine-Given - https://github.com/searls/jasmine-given ‣ Jasmine-jQuery - https://github.com/velesin/jasmine-jquery ‣ Jasmine-Stealth - https://github.com/searls/jasmine-stealth 20 CRASHLYTICS CONFIDENTIAL © 2012. All rights reserved
  • 21. Thank You (we’re hiring) Mark Roseboom Crashlytics 21 CRASHLYTICS CONFIDENTIAL © 2013. All rights reserved