SlideShare a Scribd company logo
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?

More Related Content

What's hot

Node.js exception handling
Node.js exception handlingNode.js exception handling
Node.js exception handling
Minh 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 Example
PVS-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 Application
Bill Heaton
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
Jim Lynch
 
Unit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with JasmineUnit Testing Lightning Components with Jasmine
Unit Testing Lightning Components with Jasmine
Keir Bowden
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
Harshad 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 Django
Psalms Kalu
 
PHPUnit
PHPUnitPHPUnit
Rtt preso
Rtt presoRtt preso
Rtt preso
fdschoeneman
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answers
kavinilavuG
 
Automated tests
Automated testsAutomated tests
Automated tests
Damian Sromek
 
Protractor survival guide
Protractor survival guideProtractor survival guide
Protractor survival guide
László Andrási
 
wtst3_pettichord3
wtst3_pettichord3wtst3_pettichord3
wtst3_pettichord3
tutorialsruby
 
Protractor training
Protractor trainingProtractor training
Protractor training
Sergiy Stotskiy
 
Automated Testing in Django
Automated Testing in DjangoAutomated Testing in Django
Automated Testing in Django
Loek van Gent
 
Jasmine with JS-Test-Driver
Jasmine with JS-Test-DriverJasmine with JS-Test-Driver
Jasmine with JS-Test-Driver
Devesh Chanchlani
 
(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
istefo
 
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
 

What's hot (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)
 

Viewers also liked

Dont turn your photoshop off
Dont turn your photoshop offDont turn your photoshop off
Dont turn your photoshop off
Igor 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 Jasmine
Evgeny 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 awesome
JavaScript 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 fishy
Igor Napierala
 
Mocha, chai and sinon
Mocha, chai and sinonMocha, chai and sinon
Mocha, chai and sinon
Andrew Dixon
 

Viewers also liked (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 to mocha sinon chai Dc jquery 4-24

Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
Priya Sharma
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
priya_trivedi
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Alessandro Giorgetti
 
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
André 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 Flex
michael.labriola
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Anuj Arora
 
Win at life with unit testing
Win at life with unit testingWin at life with unit testing
Win at life with unit testing
markstory
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
Eric Selje
 
Testacular
TestacularTestacular
Testacular
James Ford
 
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
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
Scott van Kalken
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014
Alex 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 workshop
Ketan Soni
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
michael.labriola
 
utplsql.pdf
utplsql.pdfutplsql.pdf
utplsql.pdf
vijayv991893
 
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
Peter Presnell
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
Mats Bryntse
 

Similar to 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
 

Recently uploaded

2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 

Recently uploaded (20)

2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 

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