SlideShare a Scribd company logo
1 of 21
Unit Testing JavaScript
Keir Bowden
CTO, BrightGen
@bob_buzzard
Unit Tests – They’re not just for Apex
• Introduction
• Tools
• Visualforce
• Lightning Components
• Q & A
What we’ll cover
Introduction
Why write unit tests
• Give confidence
• Reduce cost of bugs
• Produce testable code
• Promote refactoring
Introduction
No test context for client
• Changes aren’t rolled back
Side effects
• DOM manipulation
• Server calls
Challenges
JavaScript on Salesforce
Unobtrusive JavaScript
Avoid anonymous functions
Functional decomposition
• Function to decide on action
• Function to take the action
Writing Testable Code
function redirectToURL(url) {
if (“#”===url.charAt(0)) {
window.location.hash=url;
} else if (“/”===url.charAt(0))
window.location.pathname=url;
}
....
Github: bobbuzz.me.uk/JSUTSF
Public Site
• Jobs:
• bobbuzz.me.uk/1Ad25OG
• Tests:
• bobbuzz.me.uk/1PvhII3
Demo App
Tools
Pure JavaScript Unit Test Framework
Executes in-browser
From the developers of jQuery
QUnit
<apex:includeScript
value="{!$Resource.qunitJS}"/>
<apex:stylesheet
value="{!$Resource.qunitCSS}"/>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
Test markup container
Module – group of tests
Test – single test
Assert – confirm behaviour
Concepts
QUnit
QUnit.module("JOBLIST", {
beforeEach: function(assert) {
// setup code
},
afterEach : function(assert) {
// teardown code
}
});
QUnit.test("Show Progress", function( assert ) {
jobCtrl.showProgress();
});
assert.equal(jobCtrl.progressCount, 1,
"Progress count is one");
Pure JavaScript
Works with any test framework
Three key concepts
• Spies – records execution, parameters
• Stubs – Spies + replace functions
• Mocks – Stubs + expected behaviour
Sinon.JS
Sinon Stub
this.searchStub = sinon.stub(jobCtrl,
"doSearch");
var jobCtrl={
doSearch : function(ev) {
// remote call to server
}
};
jobCtrl.doSearch(event);
doSearch : function() {
// sinon stub code
}
assert.equal(this.searchStub.callCount,1,
"search called once");
this.searchStub.restore();
doSearch : function(ev) {
// remote call to server
}
$('#searchbtn').on("click",
jobCtrl.doSearch);
Code coverage!
Pure JavaScript
Works with QUnit, Mocha and Jasmine
JavaScript must be external
Blanket.JS
<apex:includeScript value="{!$Resource.blanketJS}"/>
<script src="{!$Resource.JobsJS}" data-cover="true"></script>
Blanket.JS
Visualforce
Dedicated test page
Replicate markup as required
Include JavaScript to be tested
Can capture coverage
Demo
Visualforce
Lightning Components
Components are isolated
JavaScript in controller + helper
Cannot capture coverage
Markup is fixed
How to trigger tests?
Challenges
Lightning Components
Qunit tests in helper function
• Controller method to execute helper function
Lightning test application (page equivalent)
Tests executed via event
• Fired by application
• Handled by component under test
Demo
My Solution!
Lightning Components
Unobtrusive JavaScript
Functional decomposition
Avoid anonymous functions
No client-side test context
Stubs are your best friend
Takeaways
Q & A
Keir Bowden
CTO, BrightGen
@bob_buzzard

More Related Content

What's hot

Web based automation testing on Node.js environment
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environmentYu-Lin Huang
 
Test Automation With Cucumber JVM, Selenium, and Mocha
Test Automation With Cucumber JVM, Selenium, and MochaTest Automation With Cucumber JVM, Selenium, and Mocha
Test Automation With Cucumber JVM, Selenium, and MochaSalesforce Developers
 
QA Automation testing online training
QA Automation testing online trainingQA Automation testing online training
QA Automation testing online trainingDivya Shree
 
Lap Around Visual Studio 2010 Ultimate And TFS 2010
Lap Around Visual Studio 2010 Ultimate And TFS 2010Lap Around Visual Studio 2010 Ultimate And TFS 2010
Lap Around Visual Studio 2010 Ultimate And TFS 2010Ed Blankenship
 
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil ManvarSenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil ManvarSencha
 
Web Application Testing with Selenium
Web Application Testing with Selenium Web Application Testing with Selenium
Web Application Testing with Selenium Sargis Sargsyan
 
Get responsive with Galen
Get responsive with GalenGet responsive with Galen
Get responsive with GalenThoughtworks
 
Writing better tests for your java script app
Writing better tests for your java script appWriting better tests for your java script app
Writing better tests for your java script appJakeGinnivan
 
Automated Testing With Jasmine, PhantomJS and Jenkins
Automated Testing With Jasmine, PhantomJS and JenkinsAutomated Testing With Jasmine, PhantomJS and Jenkins
Automated Testing With Jasmine, PhantomJS and JenkinsWork at Play
 
Visual AI Enhanced Testing on Dynamic Websites
Visual AI Enhanced Testing on Dynamic WebsitesVisual AI Enhanced Testing on Dynamic Websites
Visual AI Enhanced Testing on Dynamic WebsitesApplitools
 
Load testing with Visual Studio and Azure - Andrew Siemer
Load testing with Visual Studio and Azure - Andrew SiemerLoad testing with Visual Studio and Azure - Andrew Siemer
Load testing with Visual Studio and Azure - Andrew SiemerAndrew Siemer
 
Udvid din test portefølje med coded ui test og cloud load test
Udvid din test portefølje med coded ui test og cloud load testUdvid din test portefølje med coded ui test og cloud load test
Udvid din test portefølje med coded ui test og cloud load testPeter Lindberg
 
Visual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for DevelopersVisual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for DevelopersSteve Lange
 
Patterns of a "Good" Test Automation Framework, Locators & Data
Patterns of a "Good" Test Automation Framework, Locators & DataPatterns of a "Good" Test Automation Framework, Locators & Data
Patterns of a "Good" Test Automation Framework, Locators & DataAgile Testing Alliance
 
[Webinar] Test First, Fail Fast - Simplifying the Tester's Transition to DevOps
[Webinar] Test First, Fail Fast - Simplifying the Tester's Transition to DevOps[Webinar] Test First, Fail Fast - Simplifying the Tester's Transition to DevOps
[Webinar] Test First, Fail Fast - Simplifying the Tester's Transition to DevOpsKMS Technology
 

What's hot (20)

Web based automation testing on Node.js environment
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environment
 
Test Automation With Cucumber JVM, Selenium, and Mocha
Test Automation With Cucumber JVM, Selenium, and MochaTest Automation With Cucumber JVM, Selenium, and Mocha
Test Automation With Cucumber JVM, Selenium, and Mocha
 
ASP.NET & Unit Testing
ASP.NET & Unit TestingASP.NET & Unit Testing
ASP.NET & Unit Testing
 
ASP.NET 5 & Unit Testing
ASP.NET 5 & Unit TestingASP.NET 5 & Unit Testing
ASP.NET 5 & Unit Testing
 
Code stock
Code stockCode stock
Code stock
 
Cucumber ppt
Cucumber pptCucumber ppt
Cucumber ppt
 
QA Automation testing online training
QA Automation testing online trainingQA Automation testing online training
QA Automation testing online training
 
Lap Around Visual Studio 2010 Ultimate And TFS 2010
Lap Around Visual Studio 2010 Ultimate And TFS 2010Lap Around Visual Studio 2010 Ultimate And TFS 2010
Lap Around Visual Studio 2010 Ultimate And TFS 2010
 
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil ManvarSenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
 
Web Application Testing with Selenium
Web Application Testing with Selenium Web Application Testing with Selenium
Web Application Testing with Selenium
 
Get responsive with Galen
Get responsive with GalenGet responsive with Galen
Get responsive with Galen
 
Writing better tests for your java script app
Writing better tests for your java script appWriting better tests for your java script app
Writing better tests for your java script app
 
QAorHighway2016
QAorHighway2016QAorHighway2016
QAorHighway2016
 
Automated Testing With Jasmine, PhantomJS and Jenkins
Automated Testing With Jasmine, PhantomJS and JenkinsAutomated Testing With Jasmine, PhantomJS and Jenkins
Automated Testing With Jasmine, PhantomJS and Jenkins
 
Visual AI Enhanced Testing on Dynamic Websites
Visual AI Enhanced Testing on Dynamic WebsitesVisual AI Enhanced Testing on Dynamic Websites
Visual AI Enhanced Testing on Dynamic Websites
 
Load testing with Visual Studio and Azure - Andrew Siemer
Load testing with Visual Studio and Azure - Andrew SiemerLoad testing with Visual Studio and Azure - Andrew Siemer
Load testing with Visual Studio and Azure - Andrew Siemer
 
Udvid din test portefølje med coded ui test og cloud load test
Udvid din test portefølje med coded ui test og cloud load testUdvid din test portefølje med coded ui test og cloud load test
Udvid din test portefølje med coded ui test og cloud load test
 
Visual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for DevelopersVisual Studio 2010 Testing for Developers
Visual Studio 2010 Testing for Developers
 
Patterns of a "Good" Test Automation Framework, Locators & Data
Patterns of a "Good" Test Automation Framework, Locators & DataPatterns of a "Good" Test Automation Framework, Locators & Data
Patterns of a "Good" Test Automation Framework, Locators & Data
 
[Webinar] Test First, Fail Fast - Simplifying the Tester's Transition to DevOps
[Webinar] Test First, Fail Fast - Simplifying the Tester's Transition to DevOps[Webinar] Test First, Fail Fast - Simplifying the Tester's Transition to DevOps
[Webinar] Test First, Fail Fast - Simplifying the Tester's Transition to DevOps
 

Viewers also liked

Lean Startup for AaltoES Summer of Startups
Lean Startup for AaltoES Summer of StartupsLean Startup for AaltoES Summer of Startups
Lean Startup for AaltoES Summer of StartupsMarko Taipale
 
Slide 04 - Otaciso, Digelvânia e Silvana
Slide 04 - Otaciso, Digelvânia e SilvanaSlide 04 - Otaciso, Digelvânia e Silvana
Slide 04 - Otaciso, Digelvânia e Silvanarafaelly04
 
Brightspace Spring Release 2016
Brightspace Spring Release 2016Brightspace Spring Release 2016
Brightspace Spring Release 2016D2L
 
8281 Gefahr der Überheblichkeit ....
8281   Gefahr der Überheblichkeit ....8281   Gefahr der Überheblichkeit ....
8281 Gefahr der Überheblichkeit ....Marianne Zipf
 
Spring 2011 Current Projects
Spring 2011 Current ProjectsSpring 2011 Current Projects
Spring 2011 Current Projectsgrantml
 
Ana maria araujo calderon trabajo social redvolucion leidis
Ana maria araujo calderon trabajo social redvolucion leidisAna maria araujo calderon trabajo social redvolucion leidis
Ana maria araujo calderon trabajo social redvolucion leidisRedvolucionCesarNorte
 
3 ways to value your business
3 ways to value your business3 ways to value your business
3 ways to value your businessEquidam
 
GBI 2016 Asia - Hong Kong Launch Presentation 270916
GBI 2016 Asia - Hong Kong Launch Presentation 270916GBI 2016 Asia - Hong Kong Launch Presentation 270916
GBI 2016 Asia - Hong Kong Launch Presentation 270916Ipsos UK
 
Golden rules from online community facilitators
Golden rules from online  community facilitatorsGolden rules from online  community facilitators
Golden rules from online community facilitatorsMichael Norton
 
Enterprise Mobility Transforming Public Service and Citizen Engagement
Enterprise Mobility Transforming Public Service and Citizen EngagementEnterprise Mobility Transforming Public Service and Citizen Engagement
Enterprise Mobility Transforming Public Service and Citizen EngagementSAP Asia Pacific
 
Strata Singapore: Gearpump Real time DAG-Processing with Akka at Scale
Strata Singapore: GearpumpReal time DAG-Processing with Akka at ScaleStrata Singapore: GearpumpReal time DAG-Processing with Akka at Scale
Strata Singapore: Gearpump Real time DAG-Processing with Akka at ScaleSean Zhong
 
20151205japanr
20151205japanr20151205japanr
20151205japanrMed_KU
 
Iconic AP images of the 20th century
Iconic AP images of the 20th centuryIconic AP images of the 20th century
Iconic AP images of the 20th centuryguimera
 
Android app development – what you should not
Android app development – what you should notAndroid app development – what you should not
Android app development – what you should notmanisha ips
 
How Reebok Uses Employee Generated Content to Amplify Advocacy
How Reebok Uses Employee Generated Content to Amplify Advocacy How Reebok Uses Employee Generated Content to Amplify Advocacy
How Reebok Uses Employee Generated Content to Amplify Advocacy SocialChorus
 
Market Opportunity
Market OpportunityMarket Opportunity
Market OpportunityDavidCC2
 

Viewers also liked (20)

Lean Startup for AaltoES Summer of Startups
Lean Startup for AaltoES Summer of StartupsLean Startup for AaltoES Summer of Startups
Lean Startup for AaltoES Summer of Startups
 
Slide 04 - Otaciso, Digelvânia e Silvana
Slide 04 - Otaciso, Digelvânia e SilvanaSlide 04 - Otaciso, Digelvânia e Silvana
Slide 04 - Otaciso, Digelvânia e Silvana
 
딥 시큐리티
딥 시큐리티딥 시큐리티
딥 시큐리티
 
Brightspace Spring Release 2016
Brightspace Spring Release 2016Brightspace Spring Release 2016
Brightspace Spring Release 2016
 
8281 Gefahr der Überheblichkeit ....
8281   Gefahr der Überheblichkeit ....8281   Gefahr der Überheblichkeit ....
8281 Gefahr der Überheblichkeit ....
 
Spring 2011 Current Projects
Spring 2011 Current ProjectsSpring 2011 Current Projects
Spring 2011 Current Projects
 
CA concepts, principles and practices Kitui
CA concepts, principles and practices   KituiCA concepts, principles and practices   Kitui
CA concepts, principles and practices Kitui
 
Инновации в рекламном бизнесе
Инновации в рекламном бизнесеИнновации в рекламном бизнесе
Инновации в рекламном бизнесе
 
Open Government Data - Zwei Beispiele der Community-Einbindung
Open Government Data - Zwei Beispiele der Community-EinbindungOpen Government Data - Zwei Beispiele der Community-Einbindung
Open Government Data - Zwei Beispiele der Community-Einbindung
 
Ana maria araujo calderon trabajo social redvolucion leidis
Ana maria araujo calderon trabajo social redvolucion leidisAna maria araujo calderon trabajo social redvolucion leidis
Ana maria araujo calderon trabajo social redvolucion leidis
 
3 ways to value your business
3 ways to value your business3 ways to value your business
3 ways to value your business
 
GBI 2016 Asia - Hong Kong Launch Presentation 270916
GBI 2016 Asia - Hong Kong Launch Presentation 270916GBI 2016 Asia - Hong Kong Launch Presentation 270916
GBI 2016 Asia - Hong Kong Launch Presentation 270916
 
Golden rules from online community facilitators
Golden rules from online  community facilitatorsGolden rules from online  community facilitators
Golden rules from online community facilitators
 
Enterprise Mobility Transforming Public Service and Citizen Engagement
Enterprise Mobility Transforming Public Service and Citizen EngagementEnterprise Mobility Transforming Public Service and Citizen Engagement
Enterprise Mobility Transforming Public Service and Citizen Engagement
 
Strata Singapore: Gearpump Real time DAG-Processing with Akka at Scale
Strata Singapore: GearpumpReal time DAG-Processing with Akka at ScaleStrata Singapore: GearpumpReal time DAG-Processing with Akka at Scale
Strata Singapore: Gearpump Real time DAG-Processing with Akka at Scale
 
20151205japanr
20151205japanr20151205japanr
20151205japanr
 
Iconic AP images of the 20th century
Iconic AP images of the 20th centuryIconic AP images of the 20th century
Iconic AP images of the 20th century
 
Android app development – what you should not
Android app development – what you should notAndroid app development – what you should not
Android app development – what you should not
 
How Reebok Uses Employee Generated Content to Amplify Advocacy
How Reebok Uses Employee Generated Content to Amplify Advocacy How Reebok Uses Employee Generated Content to Amplify Advocacy
How Reebok Uses Employee Generated Content to Amplify Advocacy
 
Market Opportunity
Market OpportunityMarket Opportunity
Market Opportunity
 

Similar to JavaScript Unit Testing

Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum
 
Binary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code TestingBinary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code TestingBinary Studio
 
Rethinking Testing
Rethinking TestingRethinking Testing
Rethinking Testingpdejuan
 
Putting the 'ctions' in Azure Fun-ctions
Putting the 'ctions' in Azure Fun-ctionsPutting the 'ctions' in Azure Fun-ctions
Putting the 'ctions' in Azure Fun-ctionsNullOps
 
Level Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit TestingLevel Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit TestingGordon Bockus
 
Gradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build timesGradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build timesRene Gröschke
 
Continuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases WeeklyContinuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases WeeklyRightScale
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Hong Tat Yew
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETBen Hall
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testingMats Bryntse
 
Test driven development_continuous_integration
Test driven development_continuous_integrationTest driven development_continuous_integration
Test driven development_continuous_integrationhaochenglee
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Codecamp Romania
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Wojciech Seliga
 
Setting Up CircleCI Workflows for Your Salesforce Apps
Setting Up CircleCI Workflows for Your Salesforce AppsSetting Up CircleCI Workflows for Your Salesforce Apps
Setting Up CircleCI Workflows for Your Salesforce AppsDaniel Stange
 
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien
 
Continuous Integration on AWS
Continuous Integration on AWSContinuous Integration on AWS
Continuous Integration on AWSPetar Petrov
 
Using Selenium to Improve a Teams Development Cycle
Using Selenium to Improve a Teams Development CycleUsing Selenium to Improve a Teams Development Cycle
Using Selenium to Improve a Teams Development Cycleseleniumconf
 
From legacy to DDD (slides for the screencast)
From legacy to DDD (slides for the screencast)From legacy to DDD (slides for the screencast)
From legacy to DDD (slides for the screencast)Andrzej Krzywda
 
TDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
TDD for APIs @ Europython 2015, Bilbao by Michael KuehneTDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
TDD for APIs @ Europython 2015, Bilbao by Michael KuehneMichael Kuehne-Schlinkert
 

Similar to JavaScript Unit Testing (20)

Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
 
Binary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code TestingBinary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code Testing
 
NET Code Testing
NET Code TestingNET Code Testing
NET Code Testing
 
Rethinking Testing
Rethinking TestingRethinking Testing
Rethinking Testing
 
Putting the 'ctions' in Azure Fun-ctions
Putting the 'ctions' in Azure Fun-ctionsPutting the 'ctions' in Azure Fun-ctions
Putting the 'ctions' in Azure Fun-ctions
 
Level Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit TestingLevel Up Your Salesforce Unit Testing
Level Up Your Salesforce Unit Testing
 
Gradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build timesGradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build times
 
Continuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases WeeklyContinuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases Weekly
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
Test driven development_continuous_integration
Test driven development_continuous_integrationTest driven development_continuous_integration
Test driven development_continuous_integration
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014
 
Setting Up CircleCI Workflows for Your Salesforce Apps
Setting Up CircleCI Workflows for Your Salesforce AppsSetting Up CircleCI Workflows for Your Salesforce Apps
Setting Up CircleCI Workflows for Your Salesforce Apps
 
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developersChris O'Brien - Best bits of Azure for Office 365/SharePoint developers
Chris O'Brien - Best bits of Azure for Office 365/SharePoint developers
 
Continuous Integration on AWS
Continuous Integration on AWSContinuous Integration on AWS
Continuous Integration on AWS
 
Using Selenium to Improve a Teams Development Cycle
Using Selenium to Improve a Teams Development CycleUsing Selenium to Improve a Teams Development Cycle
Using Selenium to Improve a Teams Development Cycle
 
From legacy to DDD (slides for the screencast)
From legacy to DDD (slides for the screencast)From legacy to DDD (slides for the screencast)
From legacy to DDD (slides for the screencast)
 
TDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
TDD for APIs @ Europython 2015, Bilbao by Michael KuehneTDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
TDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
 

More from Keir Bowden

LC 2022 - Second Generation Packaging
LC 2022 - Second Generation PackagingLC 2022 - Second Generation Packaging
LC 2022 - Second Generation PackagingKeir Bowden
 
Mutation Testing.pdf
Mutation Testing.pdfMutation Testing.pdf
Mutation Testing.pdfKeir Bowden
 
London Non-Profit Spring 22 Salesforce Release
London Non-Profit Spring 22 Salesforce ReleaseLondon Non-Profit Spring 22 Salesforce Release
London Non-Profit Spring 22 Salesforce ReleaseKeir Bowden
 
London Salesforce Developer January 2022
London Salesforce Developer January 2022London Salesforce Developer January 2022
London Salesforce Developer January 2022Keir Bowden
 
Winter 22 for Developers
Winter 22 for DevelopersWinter 22 for Developers
Winter 22 for DevelopersKeir Bowden
 
Londons Calling 2021
Londons Calling 2021Londons Calling 2021
Londons Calling 2021Keir Bowden
 
London Salesforce Developers TDX 20 Global Gathering
London Salesforce Developers TDX 20 Global GatheringLondon Salesforce Developers TDX 20 Global Gathering
London Salesforce Developers TDX 20 Global GatheringKeir Bowden
 
Helsinki developer group march 2020
Helsinki developer group march 2020Helsinki developer group march 2020
Helsinki developer group march 2020Keir Bowden
 
London's calling 2020 Documentor Plug-In
London's calling 2020 Documentor Plug-InLondon's calling 2020 Documentor Plug-In
London's calling 2020 Documentor Plug-InKeir Bowden
 
Lightning User Interface Testing with Selenium and Node JS
Lightning User Interface Testing with Selenium and Node JSLightning User Interface Testing with Selenium and Node JS
Lightning User Interface Testing with Selenium and Node JSKeir Bowden
 
Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet Keir Bowden
 
Salesforce Spring 19 release top 10 Features
Salesforce Spring 19 release top 10 FeaturesSalesforce Spring 19 release top 10 Features
Salesforce Spring 19 release top 10 FeaturesKeir Bowden
 
UI Testing with Selenium and Node - London's Calling 2019
UI Testing with Selenium and Node - London's Calling 2019UI Testing with Selenium and Node - London's Calling 2019
UI Testing with Selenium and Node - London's Calling 2019Keir Bowden
 
Salesforce Winter 19 release top 10 features
Salesforce Winter 19 release top 10 featuresSalesforce Winter 19 release top 10 features
Salesforce Winter 19 release top 10 featuresKeir Bowden
 
Quickstart Templates with the Salesforce CLI
Quickstart Templates with the Salesforce CLIQuickstart Templates with the Salesforce CLI
Quickstart Templates with the Salesforce CLIKeir Bowden
 
TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018Keir Bowden
 
Getting started with public speaking
Getting started with public speakingGetting started with public speaking
Getting started with public speakingKeir Bowden
 
London's Calling 2018 - No Connection, No Problem
London's Calling 2018 - No Connection, No ProblemLondon's Calling 2018 - No Connection, No Problem
London's Calling 2018 - No Connection, No ProblemKeir Bowden
 
No Connection? No Problem!
No Connection? No Problem!No Connection? No Problem!
No Connection? No Problem!Keir Bowden
 

More from Keir Bowden (20)

LC 2022 - Second Generation Packaging
LC 2022 - Second Generation PackagingLC 2022 - Second Generation Packaging
LC 2022 - Second Generation Packaging
 
Mutation Testing.pdf
Mutation Testing.pdfMutation Testing.pdf
Mutation Testing.pdf
 
London Non-Profit Spring 22 Salesforce Release
London Non-Profit Spring 22 Salesforce ReleaseLondon Non-Profit Spring 22 Salesforce Release
London Non-Profit Spring 22 Salesforce Release
 
London Salesforce Developer January 2022
London Salesforce Developer January 2022London Salesforce Developer January 2022
London Salesforce Developer January 2022
 
Winter 22 for Developers
Winter 22 for DevelopersWinter 22 for Developers
Winter 22 for Developers
 
Londons Calling 2021
Londons Calling 2021Londons Calling 2021
Londons Calling 2021
 
London Salesforce Developers TDX 20 Global Gathering
London Salesforce Developers TDX 20 Global GatheringLondon Salesforce Developers TDX 20 Global Gathering
London Salesforce Developers TDX 20 Global Gathering
 
Helsinki developer group march 2020
Helsinki developer group march 2020Helsinki developer group march 2020
Helsinki developer group march 2020
 
London's calling 2020 Documentor Plug-In
London's calling 2020 Documentor Plug-InLondon's calling 2020 Documentor Plug-In
London's calling 2020 Documentor Plug-In
 
Lightning User Interface Testing with Selenium and Node JS
Lightning User Interface Testing with Selenium and Node JSLightning User Interface Testing with Selenium and Node JS
Lightning User Interface Testing with Selenium and Node JS
 
Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet Salesforce CLI Cheat Sheet
Salesforce CLI Cheat Sheet
 
Salesforce Spring 19 release top 10 Features
Salesforce Spring 19 release top 10 FeaturesSalesforce Spring 19 release top 10 Features
Salesforce Spring 19 release top 10 Features
 
UI Testing with Selenium and Node - London's Calling 2019
UI Testing with Selenium and Node - London's Calling 2019UI Testing with Selenium and Node - London's Calling 2019
UI Testing with Selenium and Node - London's Calling 2019
 
Salesforce Winter 19 release top 10 features
Salesforce Winter 19 release top 10 featuresSalesforce Winter 19 release top 10 features
Salesforce Winter 19 release top 10 features
 
Quickstart Templates with the Salesforce CLI
Quickstart Templates with the Salesforce CLIQuickstart Templates with the Salesforce CLI
Quickstart Templates with the Salesforce CLI
 
TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018TrailheaDX Global Gathering London 2018
TrailheaDX Global Gathering London 2018
 
Getting started with public speaking
Getting started with public speakingGetting started with public speaking
Getting started with public speaking
 
Salesforce CLI
Salesforce CLISalesforce CLI
Salesforce CLI
 
London's Calling 2018 - No Connection, No Problem
London's Calling 2018 - No Connection, No ProblemLondon's Calling 2018 - No Connection, No Problem
London's Calling 2018 - No Connection, No Problem
 
No Connection? No Problem!
No Connection? No Problem!No Connection? No Problem!
No Connection? No Problem!
 

Recently uploaded

Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Excelmac1
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一Fs
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一Fs
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Dana Luther
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一Fs
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Lucknow
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一Fs
 

Recently uploaded (20)

Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...Blepharitis inflammation of eyelid symptoms cause everything included along w...
Blepharitis inflammation of eyelid symptoms cause everything included along w...
 
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
定制(Management毕业证书)新加坡管理大学毕业证成绩单原版一比一
 
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
定制(UAL学位证)英国伦敦艺术大学毕业证成绩单原版一比一
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
Packaging the Monolith - PHP Tek 2024 (Breaking it down one bite at a time)
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
定制(AUT毕业证书)新西兰奥克兰理工大学毕业证成绩单原版一比一
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja VipCall Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
Call Girls Service Adil Nagar 7001305949 Need escorts Service Pooja Vip
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
定制(Lincoln毕业证书)新西兰林肯大学毕业证成绩单原版一比一
 

JavaScript Unit Testing

  • 1. Unit Testing JavaScript Keir Bowden CTO, BrightGen @bob_buzzard Unit Tests – They’re not just for Apex
  • 2. • Introduction • Tools • Visualforce • Lightning Components • Q & A What we’ll cover
  • 4. Why write unit tests • Give confidence • Reduce cost of bugs • Produce testable code • Promote refactoring Introduction
  • 5. No test context for client • Changes aren’t rolled back Side effects • DOM manipulation • Server calls Challenges JavaScript on Salesforce
  • 6. Unobtrusive JavaScript Avoid anonymous functions Functional decomposition • Function to decide on action • Function to take the action Writing Testable Code function redirectToURL(url) { if (“#”===url.charAt(0)) { window.location.hash=url; } else if (“/”===url.charAt(0)) window.location.pathname=url; } ....
  • 7. Github: bobbuzz.me.uk/JSUTSF Public Site • Jobs: • bobbuzz.me.uk/1Ad25OG • Tests: • bobbuzz.me.uk/1PvhII3 Demo App
  • 9. Pure JavaScript Unit Test Framework Executes in-browser From the developers of jQuery QUnit <apex:includeScript value="{!$Resource.qunitJS}"/> <apex:stylesheet value="{!$Resource.qunitCSS}"/> <div id="qunit"></div> <div id="qunit-fixture"></div> Test markup container
  • 10. Module – group of tests Test – single test Assert – confirm behaviour Concepts QUnit QUnit.module("JOBLIST", { beforeEach: function(assert) { // setup code }, afterEach : function(assert) { // teardown code } }); QUnit.test("Show Progress", function( assert ) { jobCtrl.showProgress(); }); assert.equal(jobCtrl.progressCount, 1, "Progress count is one");
  • 11. Pure JavaScript Works with any test framework Three key concepts • Spies – records execution, parameters • Stubs – Spies + replace functions • Mocks – Stubs + expected behaviour Sinon.JS
  • 12. Sinon Stub this.searchStub = sinon.stub(jobCtrl, "doSearch"); var jobCtrl={ doSearch : function(ev) { // remote call to server } }; jobCtrl.doSearch(event); doSearch : function() { // sinon stub code } assert.equal(this.searchStub.callCount,1, "search called once"); this.searchStub.restore(); doSearch : function(ev) { // remote call to server } $('#searchbtn').on("click", jobCtrl.doSearch);
  • 13. Code coverage! Pure JavaScript Works with QUnit, Mocha and Jasmine JavaScript must be external Blanket.JS <apex:includeScript value="{!$Resource.blanketJS}"/> <script src="{!$Resource.JobsJS}" data-cover="true"></script>
  • 16. Dedicated test page Replicate markup as required Include JavaScript to be tested Can capture coverage Demo Visualforce
  • 18. Components are isolated JavaScript in controller + helper Cannot capture coverage Markup is fixed How to trigger tests? Challenges Lightning Components
  • 19. Qunit tests in helper function • Controller method to execute helper function Lightning test application (page equivalent) Tests executed via event • Fired by application • Handled by component under test Demo My Solution! Lightning Components
  • 20. Unobtrusive JavaScript Functional decomposition Avoid anonymous functions No client-side test context Stubs are your best friend Takeaways
  • 21. Q & A Keir Bowden CTO, BrightGen @bob_buzzard