SlideShare une entreprise Scribd logo
1  sur  45
Télécharger pour lire hors ligne
Javascript Unit Testing with xUnit.js
Building cleaner APIs, faster!
John Buchanan, salesforce.com, inc.
Lead Member of Technical Staff
Safe harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties
materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results
expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be
deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other
financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any
statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new
functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our
operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any
litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our
relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our
service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to
larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is
included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent
fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor
Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently
available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions
based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these
forward-looking statements.
Challenges:
1. What are some of the problems with testing javascript?
Challenges:
1. What are some of the problems with testing javascript?
• Boundary Control (Web requests, DOM access)
Challenges:
1. What are some of the problems with testing javascript?
• Boundary Control (Web requests, DOM access)
• Automation / Continuous Integration
Challenges:
1. What are some of the problems with testing javascript?
• Boundary Control (Web requests, DOM access)
• Automation / Continuous Integration
• Design Dependencies, Encapsulation
Challenges:
2. What are the differences between unit and integration tests?
Challenges:
2. What are the differences between unit and integration tests?
• Single module or component vs. interactions between modules
Challenges:
2. What are the differences between unit and integration tests?
• Single module or component vs. interactions between modules
• Boundary Control (Web requests, DOM access)
Challenges:
2. What are the differences between unit and integration tests?
• Single module or component vs. interactions between modules
• Boundary Control (Web requests, DOM access)
• Cost to exercise in automation: Unit tests are cheap
Challenges:
2. What are the differences between unit and integration tests?
• Single module or component vs. interactions between modules
• Boundary Control (Web requests, DOM access)
• Cost to exercise in automation: Unit tests are cheap
• Dependencies are abstracted in units, included in integrations
xUnit.js
So what is

xUnit.js?
xUnit.js
A Host-Agnostic Test Engine with an
Attribution Based Console Runner
lolwut.
A brief history of

xUnit.js
xUnit.js:
• Started in 2006, open source project hosted on CodePlex
• Frustrated with typical test registration systems
• Environmental requirements were expensive (Server, browser)
• Loved the simplicity and speed of the WSH (cscript.exe)
• Starting to understand using unit tests as a design tool
Unit Tests:
• Should be easily organizable
• Must to be simple to add, minimizing “dev bounce”
• Need to be easy to run, but also run fast
• Should help enforce dependency isolation
• Could allow for custom types of decoration (Ignore, Test Category,
etc.)
Host Agnostic:
• Should support common hosts out of the box:
•Google Chrome (V8)
•Mozilla Firefox (SpiderMonkey)
•Microsoft Internet Explorer 4-11 (JScript and Chakra, via cscript.exe)
•Mozilla Rhino
• Must also be able to easily add new and special use hosts:
•JSDB
•NodeJS
•PhantomJS
Realization:
• We don’t need a web server
• We don’t even need a browser
• All we need is the engine, the test file, and the file under test.*

* Drastic simplification – wait for it… ☺
xUnit.js
A Host-Agnostic Test Engine with an
Attribution Based Console Runner
Missed Mandates:
•

•

Organizable:
• Let’s call tests “Facts”, to encourage single aspect-testing
• We’ll group Facts into “Fixtures”, based on “like behavior”
• E.g. several tests exercising a single method
Easy To
Add:
• Want to maintain registration with the test
• C# style attributes are a great [Example] of this behavior
• The syntax is valid javascript, and will be ignored!
Test
Code
[Fixture]

Source Code
function FooClass(){

function foo(){
this.foo=function(){
return “foo”;
};

[Fact]
function ReturnsFoo(){
var expected=“foo”;
}
var actual=new FooClass().foo();
Assert.Equal(expected, actual);
}
}
Successful Run:
Failures, Errors, Script Errors:
[Fixture]
function foo(){
[Fact]
function FailsEqualityAssertion(){
var expected=true;
var actual=false;
Assert.Equal(expected, actual);
}
}

Failure
Failures, Errors, Script Errors:
Failures, Errors, Script Errors:
[Fixture]
function foo(){
[Fact]
function ErrorsOnUnknownMember(){
var expected=true;
var actual={value:true}.slice(0,1);
Assert.Equal(expected, actual);
}
}

Error
Failures, Errors, Script Errors:
Failures, Errors, Script Errors:
[Fixture]
function foo(){
[Fact]
function ThrowsSyntaxErrorOnLoad(){
var expected=if(true));
var actual=false;
Assert.Equal(expected, actual);
}
}

Script Error
Failures, Errors, Script Errors:
Mocks and Stubs:
[Fact]
function MocksWindowReferenceOnHost(){
var expected="expected";
var mockWindow=Mocks.GetMock(Object.Global(), "window", expected);
var actual=null;
mockWindow(function(){
actual=window;
});
Assert.Equal(expected, actual);
}
Mocks and Stubs:
[Fact]
function ReturnsResultWindowHandle(){
var expected="expected";
var windowStub=Stubs.GetObject(
{open:{returnValue:expected}},
{location:"known/url"}
);
var actual=openResults(windowStub);
Assert.Equal(expected, actual);
}

function openResults(
targetWindow
){
var resultsWindow =
targetWindow.open(
"results/url"
);
return resultsWindow;
}
Data-Driven
Tests:Data(1,2,3,4)]
[Fact,
function VerifiesDataIsInRange(data){
var expectedLow = 1;
var expectedHigh = 3;
var actual=data;
Assert.InRange(actual,expectedLow,expectedHigh);
}
Usage:

[…]
Benefits of Use Driven Development:
• Lightweight code host improves development cycle
• No need to wait for browser to manually test most code
• Waste less time understanding emergent side effects
• Maintain confidence while refactoring
• Use unit tests to architect cleaner, more usable APIs
The Big One:
+

xUnit.js =
Challenges:
• Multiple build automation and CI systems
• OS interoperability requirements
• Large browser (javascript engine) support matrix
• Many different teams and modules, with different behaviors
• Existing tests required full system and browser automation
• Selenium tests were becoming increasingly slow and unwieldy
Solutions:
• xUnit.js integrates easily as a command line or processor task
• Out-of-box support for native file I/O strategies and host environments
• Pluggable design allows for simple override and customization patterns
• Custom output strategies allow for report and issue tracker integration
• Shell execution and boundary control obviate end-to-end setup needs
• Selenium tests can be retargeted as integration and smoke tests
Custom Enhancements:
• JSCover Support (http://tntim96.github.io/JSCover/)
• Automatic issue assignment based on changelist author
• Test health history report integration
+

xUnit.js =
Preparation:
• Determine your test matrix
• Build or acquire necessary host engines
• Identify your build system’s executable target structure
• Identify your target test directories and files
Integration:
• Create CI target, .bat file, or .sh script
cscript ./Tools/xUnit.js.Console.js ../../Tests
d8 – ./Tools/xUnit.js.Console.js -- ../../Tests
js ./Tools/xUnit.js.Console.js ../../Tests

• Customize your installation (Optional)
•Attributes (Default file import locations, etc.)
•Output strategies (Reporting, Custom xml formats)
• Integrate additional tools (Optional, but highly recommended)
•JSCover (http://tntim96.github.io/JSCover/)
Happy Coding!
xUnit.js
http://xunitjs.codeplex.com/

John Buchanan
LMTS, salesforce.com, inc.
Introduction to Javascript Unit Testing With xUnit.js

Contenu connexe

Tendances

Azure Site Recovery - BC/DR - Migrations & assessments in 60 minutes!
Azure Site Recovery - BC/DR - Migrations & assessments in 60 minutes!Azure Site Recovery - BC/DR - Migrations & assessments in 60 minutes!
Azure Site Recovery - BC/DR - Migrations & assessments in 60 minutes!Johan Biere
 
Best Practices in Cloud Security
Best Practices in Cloud SecurityBest Practices in Cloud Security
Best Practices in Cloud SecurityAlert Logic
 
Azure fundamentals
Azure   fundamentalsAzure   fundamentals
Azure fundamentalsRaju Kumar
 
Azure Training | Microsoft Azure Tutorial | Microsoft Azure Certification | E...
Azure Training | Microsoft Azure Tutorial | Microsoft Azure Certification | E...Azure Training | Microsoft Azure Tutorial | Microsoft Azure Certification | E...
Azure Training | Microsoft Azure Tutorial | Microsoft Azure Certification | E...Edureka!
 
Azure governance v4.0
Azure governance v4.0Azure governance v4.0
Azure governance v4.0Marcos Oikawa
 
Azure Key Vault - Getting Started
Azure Key Vault - Getting StartedAzure Key Vault - Getting Started
Azure Key Vault - Getting StartedTaswar Bhatti
 
Windows Azure Virtual Machines
Windows Azure Virtual MachinesWindows Azure Virtual Machines
Windows Azure Virtual MachinesClint Edmonson
 
Introduction to Azure
Introduction to AzureIntroduction to Azure
Introduction to AzureRobert Crane
 
AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...
AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...
AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...Amazon Web Services
 
Understanding Azure Disaster Recovery
Understanding Azure Disaster RecoveryUnderstanding Azure Disaster Recovery
Understanding Azure Disaster RecoveryNew Horizons Ireland
 
Introducing Azure Arc
Introducing Azure ArcIntroducing Azure Arc
Introducing Azure ArcMohamed Wali
 
Az 104 session 2 implement and manage azure webapps and container
Az 104 session 2 implement and manage azure webapps and containerAz 104 session 2 implement and manage azure webapps and container
Az 104 session 2 implement and manage azure webapps and containerAzureEzy1
 
CKmates - AWS 雲端運算 基礎服務介紹
CKmates - AWS 雲端運算 基礎服務介紹CKmates - AWS 雲端運算 基礎服務介紹
CKmates - AWS 雲端運算 基礎服務介紹均民 戴
 
[Azure Governance] Lesson 3 : Azure Tags
[Azure Governance] Lesson 3 : Azure Tags[Azure Governance] Lesson 3 : Azure Tags
[Azure Governance] Lesson 3 : Azure Tags☁ Hicham KADIRI ☁
 
Dapr: distributed application runtime
Dapr: distributed application runtimeDapr: distributed application runtime
Dapr: distributed application runtimeMoaid Hathot
 
Landing Zones - Creating a Foundation for Your AWS Migrations
Landing Zones - Creating a Foundation for Your AWS MigrationsLanding Zones - Creating a Foundation for Your AWS Migrations
Landing Zones - Creating a Foundation for Your AWS MigrationsAmazon Web Services
 
AWS Security Best Practices (March 2017)
AWS Security Best Practices (March 2017)AWS Security Best Practices (March 2017)
AWS Security Best Practices (March 2017)Julien SIMON
 

Tendances (20)

Azure Site Recovery - BC/DR - Migrations & assessments in 60 minutes!
Azure Site Recovery - BC/DR - Migrations & assessments in 60 minutes!Azure Site Recovery - BC/DR - Migrations & assessments in 60 minutes!
Azure Site Recovery - BC/DR - Migrations & assessments in 60 minutes!
 
Best Practices in Cloud Security
Best Practices in Cloud SecurityBest Practices in Cloud Security
Best Practices in Cloud Security
 
Azure fundamentals
Azure   fundamentalsAzure   fundamentals
Azure fundamentals
 
Azure Training | Microsoft Azure Tutorial | Microsoft Azure Certification | E...
Azure Training | Microsoft Azure Tutorial | Microsoft Azure Certification | E...Azure Training | Microsoft Azure Tutorial | Microsoft Azure Certification | E...
Azure Training | Microsoft Azure Tutorial | Microsoft Azure Certification | E...
 
Azure: PaaS or IaaS
Azure: PaaS or IaaSAzure: PaaS or IaaS
Azure: PaaS or IaaS
 
Azure governance v4.0
Azure governance v4.0Azure governance v4.0
Azure governance v4.0
 
Aws config
Aws configAws config
Aws config
 
Azure Key Vault - Getting Started
Azure Key Vault - Getting StartedAzure Key Vault - Getting Started
Azure Key Vault - Getting Started
 
Windows Azure Virtual Machines
Windows Azure Virtual MachinesWindows Azure Virtual Machines
Windows Azure Virtual Machines
 
Introduction to Azure
Introduction to AzureIntroduction to Azure
Introduction to Azure
 
AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...
AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...
AWS re:Invent 2016: DNS Demystified: Getting Started with Amazon Route 53, fe...
 
Understanding Azure Disaster Recovery
Understanding Azure Disaster RecoveryUnderstanding Azure Disaster Recovery
Understanding Azure Disaster Recovery
 
DevOps: Infrastructure as Code
DevOps: Infrastructure as CodeDevOps: Infrastructure as Code
DevOps: Infrastructure as Code
 
Introducing Azure Arc
Introducing Azure ArcIntroducing Azure Arc
Introducing Azure Arc
 
Az 104 session 2 implement and manage azure webapps and container
Az 104 session 2 implement and manage azure webapps and containerAz 104 session 2 implement and manage azure webapps and container
Az 104 session 2 implement and manage azure webapps and container
 
CKmates - AWS 雲端運算 基礎服務介紹
CKmates - AWS 雲端運算 基礎服務介紹CKmates - AWS 雲端運算 基礎服務介紹
CKmates - AWS 雲端運算 基礎服務介紹
 
[Azure Governance] Lesson 3 : Azure Tags
[Azure Governance] Lesson 3 : Azure Tags[Azure Governance] Lesson 3 : Azure Tags
[Azure Governance] Lesson 3 : Azure Tags
 
Dapr: distributed application runtime
Dapr: distributed application runtimeDapr: distributed application runtime
Dapr: distributed application runtime
 
Landing Zones - Creating a Foundation for Your AWS Migrations
Landing Zones - Creating a Foundation for Your AWS MigrationsLanding Zones - Creating a Foundation for Your AWS Migrations
Landing Zones - Creating a Foundation for Your AWS Migrations
 
AWS Security Best Practices (March 2017)
AWS Security Best Practices (March 2017)AWS Security Best Practices (March 2017)
AWS Security Best Practices (March 2017)
 

Similaire à Introduction to Javascript Unit Testing With xUnit.js

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
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and TestingSalesforce Developers
 
Self-Service Secure Test and Release Pipelines
Self-Service Secure Test and Release PipelinesSelf-Service Secure Test and Release Pipelines
Self-Service Secure Test and Release PipelinesSalesforce Engineering
 
Advanced Application Lifecycle Managment
Advanced Application Lifecycle ManagmentAdvanced Application Lifecycle Managment
Advanced Application Lifecycle ManagmentSalesforce Developers
 
DevOps in Salesforce AppCloud
DevOps in Salesforce AppCloudDevOps in Salesforce AppCloud
DevOps in Salesforce AppCloudrsg00usa
 
Automating the Impossible: End to End Team Development for ISVs (October 14, ...
Automating the Impossible: End to End Team Development for ISVs (October 14, ...Automating the Impossible: End to End Team Development for ISVs (October 14, ...
Automating the Impossible: End to End Team Development for ISVs (October 14, ...Salesforce Partners
 
Quit Jesting and Test your Lightning Web Components, Phillipe Ozil
Quit Jesting and Test your Lightning Web Components, Phillipe OzilQuit Jesting and Test your Lightning Web Components, Phillipe Ozil
Quit Jesting and Test your Lightning Web Components, Phillipe OzilCzechDreamin
 
Salesforce API Series: Release Management with the Metadata API webinar
Salesforce API Series: Release Management with the Metadata API webinarSalesforce API Series: Release Management with the Metadata API webinar
Salesforce API Series: Release Management with the Metadata API webinarSalesforce Developers
 
Automating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous IntegrationAutomating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous IntegrationSebastian Wagner
 
ApexUnit: Open source test framework for apex
ApexUnit: Open source test framework for apexApexUnit: Open source test framework for apex
ApexUnit: Open source test framework for apexVamshidhar Gandham
 
Meet The Welkin Suite IDE: Product Overview
Meet The Welkin Suite IDE: Product OverviewMeet The Welkin Suite IDE: Product Overview
Meet The Welkin Suite IDE: Product OverviewSalesforce Developers
 
Sandboxes: The Future of App Development by Evan Barnet & Pam Barnet
Sandboxes: The Future of App Development by Evan Barnet & Pam BarnetSandboxes: The Future of App Development by Evan Barnet & Pam Barnet
Sandboxes: The Future of App Development by Evan Barnet & Pam BarnetSalesforce Admins
 
Scaling to Millions of Devices and Billions of Events
Scaling to Millions of Devices and Billions of EventsScaling to Millions of Devices and Billions of Events
Scaling to Millions of Devices and Billions of EventsSalesforce Developers
 
Continuous Integration and Testing with Branch Orgs
Continuous Integration and Testing with Branch OrgsContinuous Integration and Testing with Branch Orgs
Continuous Integration and Testing with Branch OrgsSalesforce Developers
 
Introducing the Welkin Suite IDE for Salesforce
Introducing the Welkin Suite IDE for SalesforceIntroducing the Welkin Suite IDE for Salesforce
Introducing the Welkin Suite IDE for SalesforceSalesforce Developers
 
San Francisco Jenkins Area Meetup October 2016: Self-service secure test and ...
San Francisco Jenkins Area Meetup October 2016: Self-service secure test and ...San Francisco Jenkins Area Meetup October 2016: Self-service secure test and ...
San Francisco Jenkins Area Meetup October 2016: Self-service secure test and ...Andrey Falko
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit TestingKeir Bowden
 
Sucheta_kale_4.8years_QA
Sucheta_kale_4.8years_QASucheta_kale_4.8years_QA
Sucheta_kale_4.8years_QASucheta Kale
 

Similaire à Introduction to Javascript Unit Testing With xUnit.js (20)

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
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and Testing
 
Self-Service Secure Test and Release Pipelines
Self-Service Secure Test and Release PipelinesSelf-Service Secure Test and Release Pipelines
Self-Service Secure Test and Release Pipelines
 
Advanced Application Lifecycle Managment
Advanced Application Lifecycle ManagmentAdvanced Application Lifecycle Managment
Advanced Application Lifecycle Managment
 
DevOps in Salesforce AppCloud
DevOps in Salesforce AppCloudDevOps in Salesforce AppCloud
DevOps in Salesforce AppCloud
 
Automating the Impossible: End to End Team Development for ISVs (October 14, ...
Automating the Impossible: End to End Team Development for ISVs (October 14, ...Automating the Impossible: End to End Team Development for ISVs (October 14, ...
Automating the Impossible: End to End Team Development for ISVs (October 14, ...
 
Quit Jesting and Test your Lightning Web Components, Phillipe Ozil
Quit Jesting and Test your Lightning Web Components, Phillipe OzilQuit Jesting and Test your Lightning Web Components, Phillipe Ozil
Quit Jesting and Test your Lightning Web Components, Phillipe Ozil
 
Salesforce API Series: Release Management with the Metadata API webinar
Salesforce API Series: Release Management with the Metadata API webinarSalesforce API Series: Release Management with the Metadata API webinar
Salesforce API Series: Release Management with the Metadata API webinar
 
Automating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous IntegrationAutomating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous Integration
 
ApexUnit: Open source test framework for apex
ApexUnit: Open source test framework for apexApexUnit: Open source test framework for apex
ApexUnit: Open source test framework for apex
 
Meet The Welkin Suite IDE: Product Overview
Meet The Welkin Suite IDE: Product OverviewMeet The Welkin Suite IDE: Product Overview
Meet The Welkin Suite IDE: Product Overview
 
Sandboxes: The Future of App Development by Evan Barnet & Pam Barnet
Sandboxes: The Future of App Development by Evan Barnet & Pam BarnetSandboxes: The Future of App Development by Evan Barnet & Pam Barnet
Sandboxes: The Future of App Development by Evan Barnet & Pam Barnet
 
Scaling to Millions of Devices and Billions of Events
Scaling to Millions of Devices and Billions of EventsScaling to Millions of Devices and Billions of Events
Scaling to Millions of Devices and Billions of Events
 
Development Best Practices
Development Best PracticesDevelopment Best Practices
Development Best Practices
 
Continuous Integration and Testing with Branch Orgs
Continuous Integration and Testing with Branch OrgsContinuous Integration and Testing with Branch Orgs
Continuous Integration and Testing with Branch Orgs
 
Force.com Friday : Intro to Apex
Force.com Friday : Intro to Apex Force.com Friday : Intro to Apex
Force.com Friday : Intro to Apex
 
Introducing the Welkin Suite IDE for Salesforce
Introducing the Welkin Suite IDE for SalesforceIntroducing the Welkin Suite IDE for Salesforce
Introducing the Welkin Suite IDE for Salesforce
 
San Francisco Jenkins Area Meetup October 2016: Self-service secure test and ...
San Francisco Jenkins Area Meetup October 2016: Self-service secure test and ...San Francisco Jenkins Area Meetup October 2016: Self-service secure test and ...
San Francisco Jenkins Area Meetup October 2016: Self-service secure test and ...
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Sucheta_kale_4.8years_QA
Sucheta_kale_4.8years_QASucheta_kale_4.8years_QA
Sucheta_kale_4.8years_QA
 

Plus de Salesforce Developers

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSalesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceSalesforce Developers
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base ComponentsSalesforce Developers
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsSalesforce Developers
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaSalesforce Developers
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentSalesforce Developers
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsSalesforce Developers
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsSalesforce Developers
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsSalesforce Developers
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilitySalesforce Developers
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce dataSalesforce Developers
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionSalesforce Developers
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPSalesforce Developers
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceSalesforce Developers
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureSalesforce Developers
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DXSalesforce Developers
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectSalesforce Developers
 

Plus de Salesforce Developers (20)

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component Performance
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base Components
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer Highlights
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX India
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local Development
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web Components
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web Components
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer Highlights
 
Live coding with LWC
Live coding with LWCLive coding with LWC
Live coding with LWC
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura Interoperability
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce data
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCP
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in Salesforce
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data Capture
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DX
 
Get Into Lightning Flow Development
Get Into Lightning Flow DevelopmentGet Into Lightning Flow Development
Get Into Lightning Flow Development
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS Connect
 
Introduction to MuleSoft
Introduction to MuleSoftIntroduction to MuleSoft
Introduction to MuleSoft
 

Dernier

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
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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 Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Dernier (20)

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
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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 Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Introduction to Javascript Unit Testing With xUnit.js

  • 1. Javascript Unit Testing with xUnit.js Building cleaner APIs, faster! John Buchanan, salesforce.com, inc. Lead Member of Technical Staff
  • 2. Safe harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  • 3. Challenges: 1. What are some of the problems with testing javascript?
  • 4. Challenges: 1. What are some of the problems with testing javascript? • Boundary Control (Web requests, DOM access)
  • 5. Challenges: 1. What are some of the problems with testing javascript? • Boundary Control (Web requests, DOM access) • Automation / Continuous Integration
  • 6. Challenges: 1. What are some of the problems with testing javascript? • Boundary Control (Web requests, DOM access) • Automation / Continuous Integration • Design Dependencies, Encapsulation
  • 7. Challenges: 2. What are the differences between unit and integration tests?
  • 8. Challenges: 2. What are the differences between unit and integration tests? • Single module or component vs. interactions between modules
  • 9. Challenges: 2. What are the differences between unit and integration tests? • Single module or component vs. interactions between modules • Boundary Control (Web requests, DOM access)
  • 10. Challenges: 2. What are the differences between unit and integration tests? • Single module or component vs. interactions between modules • Boundary Control (Web requests, DOM access) • Cost to exercise in automation: Unit tests are cheap
  • 11. Challenges: 2. What are the differences between unit and integration tests? • Single module or component vs. interactions between modules • Boundary Control (Web requests, DOM access) • Cost to exercise in automation: Unit tests are cheap • Dependencies are abstracted in units, included in integrations
  • 14. xUnit.js A Host-Agnostic Test Engine with an Attribution Based Console Runner
  • 16. A brief history of xUnit.js
  • 17. xUnit.js: • Started in 2006, open source project hosted on CodePlex • Frustrated with typical test registration systems • Environmental requirements were expensive (Server, browser) • Loved the simplicity and speed of the WSH (cscript.exe) • Starting to understand using unit tests as a design tool
  • 18. Unit Tests: • Should be easily organizable • Must to be simple to add, minimizing “dev bounce” • Need to be easy to run, but also run fast • Should help enforce dependency isolation • Could allow for custom types of decoration (Ignore, Test Category, etc.)
  • 19. Host Agnostic: • Should support common hosts out of the box: •Google Chrome (V8) •Mozilla Firefox (SpiderMonkey) •Microsoft Internet Explorer 4-11 (JScript and Chakra, via cscript.exe) •Mozilla Rhino • Must also be able to easily add new and special use hosts: •JSDB •NodeJS •PhantomJS
  • 20. Realization: • We don’t need a web server • We don’t even need a browser • All we need is the engine, the test file, and the file under test.* * Drastic simplification – wait for it… ☺
  • 21. xUnit.js A Host-Agnostic Test Engine with an Attribution Based Console Runner
  • 22. Missed Mandates: • • Organizable: • Let’s call tests “Facts”, to encourage single aspect-testing • We’ll group Facts into “Fixtures”, based on “like behavior” • E.g. several tests exercising a single method Easy To Add: • Want to maintain registration with the test • C# style attributes are a great [Example] of this behavior • The syntax is valid javascript, and will be ignored!
  • 23. Test Code [Fixture] Source Code function FooClass(){ function foo(){ this.foo=function(){ return “foo”; }; [Fact] function ReturnsFoo(){ var expected=“foo”; } var actual=new FooClass().foo(); Assert.Equal(expected, actual); } }
  • 25. Failures, Errors, Script Errors: [Fixture] function foo(){ [Fact] function FailsEqualityAssertion(){ var expected=true; var actual=false; Assert.Equal(expected, actual); } } Failure
  • 27. Failures, Errors, Script Errors: [Fixture] function foo(){ [Fact] function ErrorsOnUnknownMember(){ var expected=true; var actual={value:true}.slice(0,1); Assert.Equal(expected, actual); } } Error
  • 29. Failures, Errors, Script Errors: [Fixture] function foo(){ [Fact] function ThrowsSyntaxErrorOnLoad(){ var expected=if(true)); var actual=false; Assert.Equal(expected, actual); } } Script Error
  • 31. Mocks and Stubs: [Fact] function MocksWindowReferenceOnHost(){ var expected="expected"; var mockWindow=Mocks.GetMock(Object.Global(), "window", expected); var actual=null; mockWindow(function(){ actual=window; }); Assert.Equal(expected, actual); }
  • 32. Mocks and Stubs: [Fact] function ReturnsResultWindowHandle(){ var expected="expected"; var windowStub=Stubs.GetObject( {open:{returnValue:expected}}, {location:"known/url"} ); var actual=openResults(windowStub); Assert.Equal(expected, actual); } function openResults( targetWindow ){ var resultsWindow = targetWindow.open( "results/url" ); return resultsWindow; }
  • 33. Data-Driven Tests:Data(1,2,3,4)] [Fact, function VerifiesDataIsInRange(data){ var expectedLow = 1; var expectedHigh = 3; var actual=data; Assert.InRange(actual,expectedLow,expectedHigh); }
  • 35. Benefits of Use Driven Development: • Lightweight code host improves development cycle • No need to wait for browser to manually test most code • Waste less time understanding emergent side effects • Maintain confidence while refactoring • Use unit tests to architect cleaner, more usable APIs The Big One:
  • 37. Challenges: • Multiple build automation and CI systems • OS interoperability requirements • Large browser (javascript engine) support matrix • Many different teams and modules, with different behaviors • Existing tests required full system and browser automation • Selenium tests were becoming increasingly slow and unwieldy
  • 38. Solutions: • xUnit.js integrates easily as a command line or processor task • Out-of-box support for native file I/O strategies and host environments • Pluggable design allows for simple override and customization patterns • Custom output strategies allow for report and issue tracker integration • Shell execution and boundary control obviate end-to-end setup needs • Selenium tests can be retargeted as integration and smoke tests
  • 39. Custom Enhancements: • JSCover Support (http://tntim96.github.io/JSCover/) • Automatic issue assignment based on changelist author • Test health history report integration
  • 41. Preparation: • Determine your test matrix • Build or acquire necessary host engines • Identify your build system’s executable target structure • Identify your target test directories and files
  • 42. Integration: • Create CI target, .bat file, or .sh script cscript ./Tools/xUnit.js.Console.js ../../Tests d8 – ./Tools/xUnit.js.Console.js -- ../../Tests js ./Tools/xUnit.js.Console.js ../../Tests • Customize your installation (Optional) •Attributes (Default file import locations, etc.) •Output strategies (Reporting, Custom xml formats) • Integrate additional tools (Optional, but highly recommended) •JSCover (http://tntim96.github.io/JSCover/)