SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Carson Banov
Testing and Tools
Testing and Tools
Mocha, Sinon, Chai
Why is testing important?
Unit testing: tests the smallest piece of code that can be tested.
These units are the building blocks of a piece of software.
Ex: A function works correctly, a class has some method and data, etc.
Unit tests are a basic guarantee that the code you have written is doing
what you want it to. "I know this code will always spit out X if it is passed
Y."
If you are developing as a team, it proves to the other coders that your
code is doing what you want it to. "This function is coded correctly and I
can prove it since these tests pass".
Allows you to build multiple 'units' together which helps in debugging. "I
know that this part of the code does this every time, so the problem is not
there."
unit testing
Functional testing tests a slice of functionality of the application.
A functional test guarantees a feature works.
Ex: A feature works correctly, some action triggers an appropriate
response, can touch multiple layers of an application.
Allows you to test that a series of units are working together correctly.
"The add new user feature works correctly."
Allows you to know when you have broken something important. "This
test broke, so my changes have changed how this works."
Allows you to map code to features. "The sign-up form is done,
because we have tests that cover a user's actions upon signing up."
Allows you to know that layers of an application are working or
interacting correctly. "I know the server is successfully talking to the
database because this test passes."
functional testing
Up to you.*
Before: write them as a planning exercise, and you know when
your feature/branch is done.
During: to figure out why it is not working, to track down bugs.
After: to test edge cases, provide proof your branch is working,
and to ensure future changes don't break this functionality.
* As long as your boss doesn’t tell you differently and you do
actually write them at some point.
when to write tests..
getting started
$ npm install mocha
$ npm install chai
$ npm install sinon
Can be used to test front-end javascript as well as a
server-side node application.
mocha
http://visionmedia.github.io/mocha/
“Mocha allows you to use any assertion library you
want, if it throws an error, it will work!”
This is where Chai comes in.
http://chaijs.com/
Essentially gives "expect", "should", and “assert”. Expect and should
keywords can be chained in ways that are quite readable.
var foo = 'bar'
foo.should.be.a('string');
foo.should.have.length(3);
expect(foo).to.be.a('string');
expect(foo).to.have.length(3);
assert.isString(foo, 'foo is a string');
Chai
back to mocha
A test suite is organized with series of functions using
the keyword "describe".
An individual test is a function specified using the
keyword "it".
more practically
Describe blocks should be well named.
We use “should …” convention to signify a test.
output
. . .
. . .
uh oh
async
Just add ‘done’.
test setup,
independence
before(), after(), beforeEach(),
afterEach()
Make sure tests are independent. You
can and should run each one on its own
and they would pass.
reusing data
Use describe blocks and setup hooks to
create desired data.
.skip and .only
Can be applied to individual tests or describe blocks.
Skip can be used while writing a test or series of tests
to unclutter the output or skip a test that is failing
because you haven’t gotten to that yet.
Less recommended: while first starting a code base
you can use skip as a placeholder for tests that you
need to write but the application doesn’t have those
parts implemented yet.
Only is great for repeatedly running just 1 test while
working on getting it to pass.
Used for local testing (don’t want any .only flags in
actual source).
.skip and .only
Be careful of letting these flags get into source.
using Sinon
http://sinonjs.org/
For testing only what you mean to test.
Provides methods for checking information about
function calls and spoofing what those function calls
return.
Spies: used to ‘wiretap’ a function.
For ensuring a function is being invoked with the right
argument(s) at the right time(s).
From Sinon: "original function will behave just as
normal."
spies
Stubs: used to replace a function with a custom
version.
Same power of inspection of a spy, but changes the
behavior of the function.
From Sinon: "the original function is not called".
Helps isolate a part of code to be tested. Can
specify different return value than the actual
function (test error handling, avoid making
unwanted network requests), even fine tune this
down to what it should return on successive calls to
the same function.
stubs
You can use the before, beforeEach, after,
afterEach hooks to persist and reset the Sinon
features.
synergy with mocha
Sinon has a built in feature for helping you keep
track of stubs, etc that you create: the sandbox.
synergy with mocha, Sinon sandbox
The sandbox can be used in beforeEach and
afterEach as well as nested.
synergy with mocha, Sinon sandbox
‘Fixtures’ are often used to be imported as fake
data that can be returned or accessed by stubbed
methods. Can even be used to store fake
functions to use as those stubs.
You can use these on/with travis-ci, jenkins
Easy to configure a basic html page that runs the
tests as well as make a grunt command to run
them.
extra stuff
links
http://visionmedia.github.io/mocha/
http://sinonjs.org/
http://chaijs.com/
http://www.elijahmanor.com/unit-test-like-a-secret-agent-with-sinon-js/
http://blog.dylants.com/2013/06/21/jenkins-and-node/
https://travis-ci.org/
https://github.com/metaskills/mocha-phantomjs
http://www.fluencia.com/
http://www.spanishdict.com/
https://www.youtube.com/watch?v=TEAbWrdB9XU
http://backbone-testing.com/
thanks
Questions?

Más contenido relacionado

La actualidad más candente

Node.js exception handling
Node.js exception handlingNode.js exception handling
Node.js exception handlingMinh Hoang
 
Complementing Unit Testing with Static Analysis, with NUnit as an Example
Complementing Unit Testing with Static Analysis, with NUnit as an ExampleComplementing Unit Testing with Static Analysis, with NUnit as an Example
Complementing Unit Testing with Static Analysis, with NUnit as an ExamplePVS-Studio
 
TestWorksConf: Exploratory Testing an API in Mob
TestWorksConf: Exploratory Testing an API in Mob TestWorksConf: Exploratory Testing an API in Mob
TestWorksConf: Exploratory Testing an API in Mob Maaret Pyhäjärvi
 
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Vladyslav Romanchenko "How to keep high code quality without e2e tests"Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Vladyslav Romanchenko "How to keep high code quality without e2e tests"Dakiry
 
Immutable Data and TypeScript in an Ember.js Application
Immutable Data and TypeScript in an Ember.js ApplicationImmutable Data and TypeScript in an Ember.js Application
Immutable Data and TypeScript in an Ember.js ApplicationBill Heaton
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular SlidesJim Lynch
 
Unit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineUnit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineKeir Bowden
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPressHarshad Mane
 
A Beginer's Guide to testing in Django
A Beginer's Guide to testing in DjangoA Beginer's Guide to testing in Django
A Beginer's Guide to testing in DjangoPsalms Kalu
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answerskavinilavuG
 
Automated Testing in Django
Automated Testing in DjangoAutomated Testing in Django
Automated Testing in DjangoLoek van Gent
 
(Unit) Testing in Emberjs – Munich Ember.js Meetup July 2014
(Unit) Testing in Emberjs – Munich Ember.js Meetup July 2014(Unit) Testing in Emberjs – Munich Ember.js Meetup July 2014
(Unit) Testing in Emberjs – Munich Ember.js Meetup July 2014istefo
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Christian Johansen
 

La actualidad más candente (20)

Node.js exception handling
Node.js exception handlingNode.js exception handling
Node.js exception handling
 
Complementing Unit Testing with Static Analysis, with NUnit as an Example
Complementing Unit Testing with Static Analysis, with NUnit as an ExampleComplementing Unit Testing with Static Analysis, with NUnit as an Example
Complementing Unit Testing with Static Analysis, with NUnit as an Example
 
TestWorksConf: Exploratory Testing an API in Mob
TestWorksConf: Exploratory Testing an API in Mob TestWorksConf: Exploratory Testing an API in Mob
TestWorksConf: Exploratory Testing an API in Mob
 
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Vladyslav Romanchenko "How to keep high code quality without e2e tests"Vladyslav Romanchenko "How to keep high code quality without e2e tests"
Vladyslav Romanchenko "How to keep high code quality without e2e tests"
 
Immutable Data and TypeScript in an Ember.js Application
Immutable Data and TypeScript in an Ember.js ApplicationImmutable Data and TypeScript in an Ember.js Application
Immutable Data and TypeScript in an Ember.js Application
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
 
Unit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineUnit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with Jasmine
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
 
A Beginer's Guide to testing in Django
A Beginer's Guide to testing in DjangoA Beginer's Guide to testing in Django
A Beginer's Guide to testing in Django
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 
Rtt preso
Rtt presoRtt preso
Rtt preso
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answers
 
Automated tests
Automated testsAutomated tests
Automated tests
 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
 
wtst3_pettichord3
wtst3_pettichord3wtst3_pettichord3
wtst3_pettichord3
 
Protractor training
Protractor trainingProtractor training
Protractor training
 
Automated Testing in Django
Automated Testing in DjangoAutomated Testing in Django
Automated Testing in Django
 
Jasmine with JS-Test-Driver
Jasmine with JS-Test-DriverJasmine with JS-Test-Driver
Jasmine with JS-Test-Driver
 
(Unit) Testing in Emberjs – Munich Ember.js Meetup July 2014
(Unit) Testing in Emberjs – Munich Ember.js Meetup July 2014(Unit) Testing in Emberjs – Munich Ember.js Meetup July 2014
(Unit) Testing in Emberjs – Munich Ember.js Meetup July 2014
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)
 

Destacado

Dont turn your photoshop off
Dont turn your photoshop offDont turn your photoshop off
Dont turn your photoshop offIgor Napierala
 
Building workflow in Javascript: Build the awesome with Gulp.
Building workflow in Javascript: Build the awesome with Gulp.   Building workflow in Javascript: Build the awesome with Gulp.
Building workflow in Javascript: Build the awesome with Gulp. JavaScript Meetup HCMC
 
Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]JavaScript Meetup HCMC
 
Testing JS with Jasmine
Testing JS with JasmineTesting JS with Jasmine
Testing JS with JasmineEvgeny Gurin
 
[Js hcm] Java script- Testing the awesome
[Js hcm] Java script- Testing the awesome[Js hcm] Java script- Testing the awesome
[Js hcm] Java script- Testing the awesomeJavaScript Meetup HCMC
 
Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Deutsche Post
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyIgor Napierala
 
Mocha, chai and sinon
Mocha, chai and sinonMocha, chai and sinon
Mocha, chai and sinonAndrew Dixon
 

Destacado (8)

Dont turn your photoshop off
Dont turn your photoshop offDont turn your photoshop off
Dont turn your photoshop off
 
Building workflow in Javascript: Build the awesome with Gulp.
Building workflow in Javascript: Build the awesome with Gulp.   Building workflow in Javascript: Build the awesome with Gulp.
Building workflow in Javascript: Build the awesome with Gulp.
 
Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]Writing testable js [by Ted Piotrowski]
Writing testable js [by Ted Piotrowski]
 
Testing JS with Jasmine
Testing JS with JasmineTesting JS with Jasmine
Testing JS with Jasmine
 
[Js hcm] Java script- Testing the awesome
[Js hcm] Java script- Testing the awesome[Js hcm] Java script- Testing the awesome
[Js hcm] Java script- Testing the awesome
 
Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)Javascript Test Automation Workshop (21.08.2014)
Javascript Test Automation Workshop (21.08.2014)
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
 
Mocha, chai and sinon
Mocha, chai and sinonMocha, chai and sinon
Mocha, chai and sinon
 

Similar a mocha sinon chai Dc jquery 4-24

Clean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesClean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesAndré de Fontana Ignacio
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flexmichael.labriola
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testingmarkstory
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfEric Selje
 
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...Applitools
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014Alex Kavanagh
 
Searching for bugs in Mono: there are hundreds of them!
Searching for bugs in Mono: there are hundreds of them!Searching for bugs in Mono: there are hundreds of them!
Searching for bugs in Mono: there are hundreds of them!PVS-Studio
 
How to fix bug or defects in software
How to fix bug or defects in software How to fix bug or defects in software
How to fix bug or defects in software Rajasekar Subramanian
 
Espresso workshop
Espresso workshopEspresso workshop
Espresso workshopKetan Soni
 
I Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingI Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingPeter Presnell
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testingMats Bryntse
 

Similar a mocha sinon chai Dc jquery 4-24 (20)

Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Clean code quotes - Citações e provocações
Clean code quotes - Citações e provocaçõesClean code quotes - Citações e provocações
Clean code quotes - Citações e provocações
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
 
Testacular
TestacularTestacular
Testacular
 
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
Testing Hourglass at Jira Frontend - by Alexey Shpakov, Sr. Developer @ Atlas...
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014
 
Searching for bugs in Mono: there are hundreds of them!
Searching for bugs in Mono: there are hundreds of them!Searching for bugs in Mono: there are hundreds of them!
Searching for bugs in Mono: there are hundreds of them!
 
How to fix bug or defects in software
How to fix bug or defects in software How to fix bug or defects in software
How to fix bug or defects in software
 
Espresso workshop
Espresso workshopEspresso workshop
Espresso workshop
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
utplsql.pdf
utplsql.pdfutplsql.pdf
utplsql.pdf
 
I Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application TestingI Smell A RAT- Rapid Application Testing
I Smell A RAT- Rapid Application Testing
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 

Último

Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Copilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform CopilotCopilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform CopilotEdgard Alejos
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainAbdul Ahad
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 

Último (20)

Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Copilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform CopilotCopilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform Copilot
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software Domain
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 

mocha sinon chai Dc jquery 4-24

  • 3. Why is testing important?
  • 4. Unit testing: tests the smallest piece of code that can be tested. These units are the building blocks of a piece of software. Ex: A function works correctly, a class has some method and data, etc. Unit tests are a basic guarantee that the code you have written is doing what you want it to. "I know this code will always spit out X if it is passed Y." If you are developing as a team, it proves to the other coders that your code is doing what you want it to. "This function is coded correctly and I can prove it since these tests pass". Allows you to build multiple 'units' together which helps in debugging. "I know that this part of the code does this every time, so the problem is not there." unit testing
  • 5. Functional testing tests a slice of functionality of the application. A functional test guarantees a feature works. Ex: A feature works correctly, some action triggers an appropriate response, can touch multiple layers of an application. Allows you to test that a series of units are working together correctly. "The add new user feature works correctly." Allows you to know when you have broken something important. "This test broke, so my changes have changed how this works." Allows you to map code to features. "The sign-up form is done, because we have tests that cover a user's actions upon signing up." Allows you to know that layers of an application are working or interacting correctly. "I know the server is successfully talking to the database because this test passes." functional testing
  • 6. Up to you.* Before: write them as a planning exercise, and you know when your feature/branch is done. During: to figure out why it is not working, to track down bugs. After: to test edge cases, provide proof your branch is working, and to ensure future changes don't break this functionality. * As long as your boss doesn’t tell you differently and you do actually write them at some point. when to write tests..
  • 7. getting started $ npm install mocha $ npm install chai $ npm install sinon Can be used to test front-end javascript as well as a server-side node application.
  • 8. mocha http://visionmedia.github.io/mocha/ “Mocha allows you to use any assertion library you want, if it throws an error, it will work!” This is where Chai comes in.
  • 9. http://chaijs.com/ Essentially gives "expect", "should", and “assert”. Expect and should keywords can be chained in ways that are quite readable. var foo = 'bar' foo.should.be.a('string'); foo.should.have.length(3); expect(foo).to.be.a('string'); expect(foo).to.have.length(3); assert.isString(foo, 'foo is a string'); Chai
  • 10. back to mocha A test suite is organized with series of functions using the keyword "describe". An individual test is a function specified using the keyword "it".
  • 11. more practically Describe blocks should be well named. We use “should …” convention to signify a test.
  • 13. uh oh
  • 15. test setup, independence before(), after(), beforeEach(), afterEach() Make sure tests are independent. You can and should run each one on its own and they would pass.
  • 16. reusing data Use describe blocks and setup hooks to create desired data.
  • 17. .skip and .only Can be applied to individual tests or describe blocks. Skip can be used while writing a test or series of tests to unclutter the output or skip a test that is failing because you haven’t gotten to that yet. Less recommended: while first starting a code base you can use skip as a placeholder for tests that you need to write but the application doesn’t have those parts implemented yet. Only is great for repeatedly running just 1 test while working on getting it to pass. Used for local testing (don’t want any .only flags in actual source).
  • 18. .skip and .only Be careful of letting these flags get into source.
  • 19. using Sinon http://sinonjs.org/ For testing only what you mean to test. Provides methods for checking information about function calls and spoofing what those function calls return.
  • 20. Spies: used to ‘wiretap’ a function. For ensuring a function is being invoked with the right argument(s) at the right time(s). From Sinon: "original function will behave just as normal." spies
  • 21. Stubs: used to replace a function with a custom version. Same power of inspection of a spy, but changes the behavior of the function. From Sinon: "the original function is not called". Helps isolate a part of code to be tested. Can specify different return value than the actual function (test error handling, avoid making unwanted network requests), even fine tune this down to what it should return on successive calls to the same function. stubs
  • 22. You can use the before, beforeEach, after, afterEach hooks to persist and reset the Sinon features. synergy with mocha
  • 23. Sinon has a built in feature for helping you keep track of stubs, etc that you create: the sandbox. synergy with mocha, Sinon sandbox
  • 24. The sandbox can be used in beforeEach and afterEach as well as nested. synergy with mocha, Sinon sandbox
  • 25. ‘Fixtures’ are often used to be imported as fake data that can be returned or accessed by stubbed methods. Can even be used to store fake functions to use as those stubs. You can use these on/with travis-ci, jenkins Easy to configure a basic html page that runs the tests as well as make a grunt command to run them. extra stuff