SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
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?

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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)
 

Destaque

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
 

Destaque (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
 

Semelhante 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
 

Semelhante 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

WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 

Último (20)

WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 

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