SlideShare a Scribd company logo
BDD - Jasmine
Agenda
• Need of TDD/BDD
• Steps to BDD
• Familiarize terminology
• Installation
• Executing jasmine
• Write tests in jasmine
• What next?
TDD
• Involves writing tests before writing the code
being tested
• Write a small test first (at this point of time no
code being written!)
• Run the test (obviously, it fails!)
• Now make the test pass (well write some code)
• Observe the design, refactor
TDD - Challenges
• As the code size increases more refactor
becomes critical
• Since most of the time the features are not pre-
determined reviewing/refactoring does prove as
time consuming and becomes expensive
So what next???
• In real time objects are the carriers
• They extend the behavior of classes
• This would be mean, “what an object does is
significantly more important!”
• It’s all behavior
BDD
• Behaviour Driven Development is an Agile
development process that comprises aspects of
– Acceptance Test Driven Planning,
– Domain Driven Design
– Test Driven Development
BDD
• BDD puts the focus on Behavior rather than
structure
• Examples
– User inputting values
– Awaiting for the feedback
– Calculations/logic
• It’s all behavior
BDD Triad
• For better communication across the levels
(Business analysts, Developers, Testers) in
software development we narrate/describe the
logical chunks as scenarios
• Given/When/Then – called as BDD triad
BDD Cycle
Jasmine
Jasmine
• It’s a BDD Framework for testing JavaScript
• Does not depend on other frameworks
• Does not require a DOM
• Clean & Obvious syntax
• Influenced by Rspec, JSSpec, Jspec
• Available as stand-alone, ruby gem, Node.js module, as
Maven plugin
Principles
• Should not be tied to any browser, framework,
platform or host language
• Should have idiomatic and unsurprising syntax
• Should work wherever JavaScript runs
• Should play well with IDE’s
Goals
• It should encourage good testing practices
• It should be simple to get start with
• It should integrate easily with continuous build
systems
Terminology
•Specs
•Suites
•describe
•it
•expect
•matchers
•mocks
•spies
Installation
•Required files/structure
•Download stand alone zip file include the lib files
<script type="text/javascript" src="lib/jasmine-1.0.0.rc1/jasmine.js"></script>  
<script type="text/javascript" src="lib/jasmine-1.0.0.rc1/jasmine-html.js"></script>  
•Include styles as well
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.0.0.rc1/jasmine.css">
Implementation/File structure
•jasmine-example/
• lib/
• jasmine-1.3.1/jasmine.js
• jasmine-1.3.1/jasmine-html.js
• jasmine-1.0.0.rc1/jasmine.css
• specs/
• SpecHelper.js
• BasicMathSpec.js
• scripts/
• BasicMath.js
http://tryjasmine.com/
describe ... it
describe accepts a
string or class.
Helps in
organizing specs
it is what describes the
spec. It optionally
takes a string
// Jasmine
describe “Calculate”, function() {
describe “#Add”, function(){
it “should give sum”, function(){
-----
-----
};
});
});
Filters
// Jasmine
var calc;
beforeEach(function(){
calc = new Calculator();
});
afterEach(function(){
calc.reset();
});
Pretty handy to create data
for each test
before runs the specified
block before each test.
after runs the specified block
after each test.
Expectations
//Jasmine
it (“should return the sum”, function(){
calc = new Calculator();
expect(calc.Add(4,5).toEqual(9));
expect(calc.Add(4,4).not.toEqual(9));
});
http://tryjasmine.com/
Specs - variables
Spec -
describe('panda',function(){
it('is happy',function(){
expect(panda).toBe('happy');
});
});
JavaScript
panda = “happy”;
Specs - variables
Spec -
describe('panda',function(){
it('is happy',function(){
expect(panda).toBe('happy');
});
});
JavaScript
panda = “happy”;
Specs - functions
Spec
describe('Hello World function',function(){
it('just prints a string',function(){
expect(helloWorld()).toEqual("Hello world!");
});
});
JavaScript
function helloWorld(){
return "Hello world!";
}
Specs –matchers
Spec
describe('Hello World function',function(){
it('just prints a string',function(){
expect(helloWorld()).toContain("world!");
});
});
JavaScript
function helloWorld(){
return "Hello world!";
}
Specs –Custom matchers
Spec
describe('Hello world', function() {
beforeEach(function() {
this.addMatchers({
toBeDivisibleByTwo: function() {
return (this.actual % 2) === 0;
}
});
});
it('is divisible by 2', function() {
expect(guessANumber()).toBeDivisibleByTwo();
});
});
Spy
• Spy are handy in tracking down the usage of dependent or
functions that are being invoked by other functions
• Take a scenario, where on the website I would like to wish the
user like Hi, Hello along with salutation Mr, Ms, Mrs
• Say I have a simple function greet() which returns plain string
• Another function which returns the salutation()
• spyOn(obj, 'method')
• expect(obj.method).toHaveBeenCalled()
Spy - usage
• spyOn(obj, 'method')
• expect(obj.method).toHaveBeenCalled()
• expect(obj.method).toHaveBeenCalled(“Hello”,”Mr”)
• obj.method.callCount
Specs – Spy
describe("User", function() {
it("calls the salutation function", function() {
var visitor = new User();
spyOn(visitor, "greetUser");
visitor.greetUser("Hello");
expect(visitor.greetUser).toHaveBeenCalled();
});
});
Specs – Functions
User = function(){};
User.prototype.greetUser = function(salutation){
return this.sayHello() + "" + salutation;
}
User.prototype.sayHello = function(){
return "Hello";
}
DEMO
What next?
• Spies
• Mocking/Faking
• coffee-script
• jasmine-jquery
• jasmine-fixture
• jasmine-stealth
Thanks
References:
http://blog.bandzarewicz.com/blog/2012/03/08/jasmine-cheat-sheet/
http://evanhahn.com/how-do-i-jasmine/
http://tobyho.com/2011/12/15/jasmine-spy-cheatsheet/
https://github.com/pivotal/jasmine/wiki/Spies

More Related Content

What's hot

Capybara testing
Capybara testingCapybara testing
Capybara testing
Futureworkz
 
How You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionHow You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in Production
BoldRadius Solutions
 
Microservices: Yes or not?
Microservices: Yes or not?Microservices: Yes or not?
Microservices: Yes or not?
Eduard Tomàs
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
All Things Open
 
Asp.net mvc 5 course module 1 overview
Asp.net mvc 5 course   module 1 overviewAsp.net mvc 5 course   module 1 overview
Asp.net mvc 5 course module 1 overview
Sergey Seletsky
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Shailendra Chauhan
 
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
Talentica Software
 
Crash Course in AngularJS + Ionic (Deep dive)
Crash Course in AngularJS + Ionic (Deep dive)Crash Course in AngularJS + Ionic (Deep dive)
Crash Course in AngularJS + Ionic (Deep dive)
ColdFusionConference
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold
 
Scal`a`ngular - Scala and Angular
Scal`a`ngular - Scala and AngularScal`a`ngular - Scala and Angular
Scal`a`ngular - Scala and Angular
Knoldus Inc.
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
Sumanth Chinthagunta
 
Exactpro Systems for KSTU Students in Kostroma
Exactpro Systems for KSTU Students in KostromaExactpro Systems for KSTU Students in Kostroma
Exactpro Systems for KSTU Students in KostromaIosif Itkin
 
Building Massive AngularJS Apps
Building Massive AngularJS AppsBuilding Massive AngularJS Apps
Building Massive AngularJS Apps
Gordon Bockus
 
Modularize JavaScript with RequireJS
Modularize JavaScript with RequireJSModularize JavaScript with RequireJS
Modularize JavaScript with RequireJSMinh Hoang
 
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Movel
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await Explained
Jeremy Likness
 
Tooling for the productive front-end developer
Tooling for the productive front-end developerTooling for the productive front-end developer
Tooling for the productive front-end developer
Maurice De Beijer [MVP]
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
Ivan Ivanov
 
Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]
Ryan Cuprak
 

What's hot (20)

Capybara testing
Capybara testingCapybara testing
Capybara testing
 
How You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in ProductionHow You Convince Your Manager To Adopt Scala.js in Production
How You Convince Your Manager To Adopt Scala.js in Production
 
Jbehave selenium
Jbehave seleniumJbehave selenium
Jbehave selenium
 
Microservices: Yes or not?
Microservices: Yes or not?Microservices: Yes or not?
Microservices: Yes or not?
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
 
Asp.net mvc 5 course module 1 overview
Asp.net mvc 5 course   module 1 overviewAsp.net mvc 5 course   module 1 overview
Asp.net mvc 5 course module 1 overview
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Web Performance & Latest in React
Web Performance & Latest in ReactWeb Performance & Latest in React
Web Performance & Latest in React
 
Crash Course in AngularJS + Ionic (Deep dive)
Crash Course in AngularJS + Ionic (Deep dive)Crash Course in AngularJS + Ionic (Deep dive)
Crash Course in AngularJS + Ionic (Deep dive)
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
Scal`a`ngular - Scala and Angular
Scal`a`ngular - Scala and AngularScal`a`ngular - Scala and Angular
Scal`a`ngular - Scala and Angular
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
 
Exactpro Systems for KSTU Students in Kostroma
Exactpro Systems for KSTU Students in KostromaExactpro Systems for KSTU Students in Kostroma
Exactpro Systems for KSTU Students in Kostroma
 
Building Massive AngularJS Apps
Building Massive AngularJS AppsBuilding Massive AngularJS Apps
Building Massive AngularJS Apps
 
Modularize JavaScript with RequireJS
Modularize JavaScript with RequireJSModularize JavaScript with RequireJS
Modularize JavaScript with RequireJS
 
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
Scaling AngularJS: Enterprise SOA on the MEAN Stack (Responsive Web & Mobile)
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await Explained
 
Tooling for the productive front-end developer
Tooling for the productive front-end developerTooling for the productive front-end developer
Tooling for the productive front-end developer
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
 
Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]
 

Viewers also liked

Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
Lars Thorup
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
Timothy Oxley
 
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
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and KarmaUnit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
Andrey Kolodnitsky
 
Karma - JS Test Runner
Karma - JS Test RunnerKarma - JS Test Runner
Karma - JS Test Runner
Sebastiano Armeli
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
JavaScript Firme: Módulos com RequireJS e BDD com Jasmine
JavaScript Firme: Módulos com RequireJS e BDD com JasmineJavaScript Firme: Módulos com RequireJS e BDD com Jasmine
JavaScript Firme: Módulos com RequireJS e BDD com Jasmine
André Willik Valenti
 
Behavior Driven GUI Testing
Behavior Driven GUI TestingBehavior Driven GUI Testing
Behavior Driven GUI Testing
Reginald Stadlbauer
 
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
Dimitar Danailov
 
Behavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & JasmineBehavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & Jasmine
Remus Langu
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
Roy Yu
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
Chiew Carol
 
Jasmine Sandler Client Case Studies- Digital Marketing Consultant - Social Me...
Jasmine Sandler Client Case Studies- Digital Marketing Consultant - Social Me...Jasmine Sandler Client Case Studies- Digital Marketing Consultant - Social Me...
Jasmine Sandler Client Case Studies- Digital Marketing Consultant - Social Me...
Jasmine Sandler
 
JAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineJAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & Jasmine
Anup Singh
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Christopher Bartling
 
Automated Testing With Jasmine, PhantomJS and Jenkins
Automated Testing With Jasmine, PhantomJS and JenkinsAutomated Testing With Jasmine, PhantomJS and Jenkins
Automated Testing With Jasmine, PhantomJS and Jenkins
Work at Play
 

Viewers also liked (20)

Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
 
Jasmine BDD for Javascript
Jasmine BDD for JavascriptJasmine BDD for Javascript
Jasmine BDD for Javascript
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
 
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
 
Unit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and KarmaUnit testing in JavaScript with Jasmine and Karma
Unit testing in JavaScript with Jasmine and Karma
 
Karma - JS Test Runner
Karma - JS Test RunnerKarma - JS Test Runner
Karma - JS Test Runner
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
 
JavaScript Firme: Módulos com RequireJS e BDD com Jasmine
JavaScript Firme: Módulos com RequireJS e BDD com JasmineJavaScript Firme: Módulos com RequireJS e BDD com Jasmine
JavaScript Firme: Módulos com RequireJS e BDD com Jasmine
 
Behavior Driven GUI Testing
Behavior Driven GUI TestingBehavior Driven GUI Testing
Behavior Driven GUI Testing
 
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
DEV.BG - Angular 1 and Jasmine (Unit Testing and TDD)
 
Behavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & JasmineBehavior Driven Development with AngularJS & Jasmine
Behavior Driven Development with AngularJS & Jasmine
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101Javascript Testing with Jasmine 101
Javascript Testing with Jasmine 101
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
 
Jasmine Sandler Client Case Studies- Digital Marketing Consultant - Social Me...
Jasmine Sandler Client Case Studies- Digital Marketing Consultant - Social Me...Jasmine Sandler Client Case Studies- Digital Marketing Consultant - Social Me...
Jasmine Sandler Client Case Studies- Digital Marketing Consultant - Social Me...
 
JAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & JasmineJAVASCRIPT Test Driven Development & Jasmine
JAVASCRIPT Test Driven Development & Jasmine
 
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
 
jasmine
jasminejasmine
jasmine
 
Automated Testing With Jasmine, PhantomJS and Jenkins
Automated Testing With Jasmine, PhantomJS and JenkinsAutomated Testing With Jasmine, PhantomJS and Jenkins
Automated Testing With Jasmine, PhantomJS and Jenkins
 

Similar to Jasmine - A BDD test framework for JavaScript

Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill Ayers
SPC Adriatics
 
How to write test in node.js
How to write test in node.jsHow to write test in node.js
How to write test in node.js
Jason Lin
 
Que nos espera a los ALM Dudes para el 2013?
Que nos espera a los ALM Dudes para el 2013?Que nos espera a los ALM Dudes para el 2013?
Que nos espera a los ALM Dudes para el 2013?
Bruno Capuano
 
From Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@LohikaFrom Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@Lohika
Ivan Verhun
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven Development
Sarah Dutkiewicz
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Ortus Solutions, Corp
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Uma Ghotikar
 
How to Use Selenium, Successfully
How to Use Selenium, SuccessfullyHow to Use Selenium, Successfully
How to Use Selenium, Successfully
Sauce Labs
 
Ast in CI/CD by Ofer Maor
Ast in CI/CD by Ofer MaorAst in CI/CD by Ofer Maor
Ast in CI/CD by Ofer Maor
DevSecCon
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
Dave Haeffner
 
Miami2015
Miami2015Miami2015
Miami2015
DevinVinson
 
Bringing DevOps to the Database
Bringing DevOps to the DatabaseBringing DevOps to the Database
Bringing DevOps to the Database
Michaela Murray
 
Tdd
TddTdd
Introduction to Testing and TDD
Introduction to Testing and TDDIntroduction to Testing and TDD
Introduction to Testing and TDD
Sarah Dutkiewicz
 
Dbops, DevOps & Ops, by Eduardo Piairo
Dbops, DevOps & Ops, by Eduardo PiairoDbops, DevOps & Ops, by Eduardo Piairo
Dbops, DevOps & Ops, by Eduardo Piairo
Agile Connect®
 
introduction v4
introduction v4introduction v4
introduction v4
transformtoit
 
Vibe Custom Development
Vibe Custom DevelopmentVibe Custom Development
Vibe Custom Development
GWAVA
 
What is this agile thing anyway
What is this agile thing anywayWhat is this agile thing anyway
What is this agile thing anyway
Lisa Van Gelder
 
Create Your Own Starter Files
Create Your Own Starter FilesCreate Your Own Starter Files
Create Your Own Starter Files
Emily Lewis
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
Malinda Kapuruge
 

Similar to Jasmine - A BDD test framework for JavaScript (20)

Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill Ayers
 
How to write test in node.js
How to write test in node.jsHow to write test in node.js
How to write test in node.js
 
Que nos espera a los ALM Dudes para el 2013?
Que nos espera a los ALM Dudes para el 2013?Que nos espera a los ALM Dudes para el 2013?
Que nos espera a los ALM Dudes para el 2013?
 
From Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@LohikaFrom Pilot to Product - Morning@Lohika
From Pilot to Product - Morning@Lohika
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven Development
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Into...
 
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
Introduction to Unit Testing, BDD and Mocking using TestBox & MockBox at Adob...
 
How to Use Selenium, Successfully
How to Use Selenium, SuccessfullyHow to Use Selenium, Successfully
How to Use Selenium, Successfully
 
Ast in CI/CD by Ofer Maor
Ast in CI/CD by Ofer MaorAst in CI/CD by Ofer Maor
Ast in CI/CD by Ofer Maor
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Miami2015
Miami2015Miami2015
Miami2015
 
Bringing DevOps to the Database
Bringing DevOps to the DatabaseBringing DevOps to the Database
Bringing DevOps to the Database
 
Tdd
TddTdd
Tdd
 
Introduction to Testing and TDD
Introduction to Testing and TDDIntroduction to Testing and TDD
Introduction to Testing and TDD
 
Dbops, DevOps & Ops, by Eduardo Piairo
Dbops, DevOps & Ops, by Eduardo PiairoDbops, DevOps & Ops, by Eduardo Piairo
Dbops, DevOps & Ops, by Eduardo Piairo
 
introduction v4
introduction v4introduction v4
introduction v4
 
Vibe Custom Development
Vibe Custom DevelopmentVibe Custom Development
Vibe Custom Development
 
What is this agile thing anyway
What is this agile thing anywayWhat is this agile thing anyway
What is this agile thing anyway
 
Create Your Own Starter Files
Create Your Own Starter FilesCreate Your Own Starter Files
Create Your Own Starter Files
 
Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
 

More from Sumanth krishna

Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
Sumanth krishna
 
Services Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJSServices Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJS
Sumanth krishna
 
Ruby Interview Questions
Ruby Interview QuestionsRuby Interview Questions
Ruby Interview Questions
Sumanth krishna
 
Ruby on Rails industry trends
Ruby on Rails industry trendsRuby on Rails industry trends
Ruby on Rails industry trends
Sumanth krishna
 
Introducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoRIntroducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoR
Sumanth krishna
 
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. A
Sumanth krishna
 
Life Pencil And U
Life Pencil And ULife Pencil And U
Life Pencil And U
Sumanth krishna
 
Ro R Based Social Networking Apps Compared
Ro R Based Social Networking Apps ComparedRo R Based Social Networking Apps Compared
Ro R Based Social Networking Apps Compared
Sumanth krishna
 
Put The Glass Down
Put The Glass DownPut The Glass Down
Put The Glass Down
Sumanth krishna
 
New Rabbit Tortoise Story
New Rabbit   Tortoise StoryNew Rabbit   Tortoise Story
New Rabbit Tortoise Story
Sumanth krishna
 
RoR relevance to startups Session @ Barcamp5 - Sumanth Krishna
RoR relevance to startups Session @ Barcamp5 - Sumanth KrishnaRoR relevance to startups Session @ Barcamp5 - Sumanth Krishna
RoR relevance to startups Session @ Barcamp5 - Sumanth Krishna
Sumanth krishna
 
Cookie - story
Cookie - storyCookie - story
Cookie - story
Sumanth krishna
 
How Brain Works against in identifying colors?
How Brain Works against in identifying colors?How Brain Works against in identifying colors?
How Brain Works against in identifying colors?Sumanth krishna
 

More from Sumanth krishna (13)

Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
 
Services Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJSServices Factory Provider Value Constant - AngularJS
Services Factory Provider Value Constant - AngularJS
 
Ruby Interview Questions
Ruby Interview QuestionsRuby Interview Questions
Ruby Interview Questions
 
Ruby on Rails industry trends
Ruby on Rails industry trendsRuby on Rails industry trends
Ruby on Rails industry trends
 
Introducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoRIntroducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoR
 
Watir Presentation Sumanth Krishna. A
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. A
 
Life Pencil And U
Life Pencil And ULife Pencil And U
Life Pencil And U
 
Ro R Based Social Networking Apps Compared
Ro R Based Social Networking Apps ComparedRo R Based Social Networking Apps Compared
Ro R Based Social Networking Apps Compared
 
Put The Glass Down
Put The Glass DownPut The Glass Down
Put The Glass Down
 
New Rabbit Tortoise Story
New Rabbit   Tortoise StoryNew Rabbit   Tortoise Story
New Rabbit Tortoise Story
 
RoR relevance to startups Session @ Barcamp5 - Sumanth Krishna
RoR relevance to startups Session @ Barcamp5 - Sumanth KrishnaRoR relevance to startups Session @ Barcamp5 - Sumanth Krishna
RoR relevance to startups Session @ Barcamp5 - Sumanth Krishna
 
Cookie - story
Cookie - storyCookie - story
Cookie - story
 
How Brain Works against in identifying colors?
How Brain Works against in identifying colors?How Brain Works against in identifying colors?
How Brain Works against in identifying colors?
 

Recently uploaded

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
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 

Recently uploaded (20)

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
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 

Jasmine - A BDD test framework for JavaScript

  • 2. Agenda • Need of TDD/BDD • Steps to BDD • Familiarize terminology • Installation • Executing jasmine • Write tests in jasmine • What next?
  • 3. TDD • Involves writing tests before writing the code being tested • Write a small test first (at this point of time no code being written!) • Run the test (obviously, it fails!) • Now make the test pass (well write some code) • Observe the design, refactor
  • 4. TDD - Challenges • As the code size increases more refactor becomes critical • Since most of the time the features are not pre- determined reviewing/refactoring does prove as time consuming and becomes expensive
  • 5. So what next??? • In real time objects are the carriers • They extend the behavior of classes • This would be mean, “what an object does is significantly more important!” • It’s all behavior
  • 6. BDD • Behaviour Driven Development is an Agile development process that comprises aspects of – Acceptance Test Driven Planning, – Domain Driven Design – Test Driven Development
  • 7. BDD • BDD puts the focus on Behavior rather than structure • Examples – User inputting values – Awaiting for the feedback – Calculations/logic • It’s all behavior
  • 8. BDD Triad • For better communication across the levels (Business analysts, Developers, Testers) in software development we narrate/describe the logical chunks as scenarios • Given/When/Then – called as BDD triad
  • 11. Jasmine • It’s a BDD Framework for testing JavaScript • Does not depend on other frameworks • Does not require a DOM • Clean & Obvious syntax • Influenced by Rspec, JSSpec, Jspec • Available as stand-alone, ruby gem, Node.js module, as Maven plugin
  • 12. Principles • Should not be tied to any browser, framework, platform or host language • Should have idiomatic and unsurprising syntax • Should work wherever JavaScript runs • Should play well with IDE’s
  • 13. Goals • It should encourage good testing practices • It should be simple to get start with • It should integrate easily with continuous build systems
  • 15. Installation •Required files/structure •Download stand alone zip file include the lib files <script type="text/javascript" src="lib/jasmine-1.0.0.rc1/jasmine.js"></script>   <script type="text/javascript" src="lib/jasmine-1.0.0.rc1/jasmine-html.js"></script>   •Include styles as well <link rel="stylesheet" type="text/css" href="lib/jasmine-1.0.0.rc1/jasmine.css">
  • 16. Implementation/File structure •jasmine-example/ • lib/ • jasmine-1.3.1/jasmine.js • jasmine-1.3.1/jasmine-html.js • jasmine-1.0.0.rc1/jasmine.css • specs/ • SpecHelper.js • BasicMathSpec.js • scripts/ • BasicMath.js
  • 18. describe ... it describe accepts a string or class. Helps in organizing specs it is what describes the spec. It optionally takes a string // Jasmine describe “Calculate”, function() { describe “#Add”, function(){ it “should give sum”, function(){ ----- ----- }; }); });
  • 19. Filters // Jasmine var calc; beforeEach(function(){ calc = new Calculator(); }); afterEach(function(){ calc.reset(); }); Pretty handy to create data for each test before runs the specified block before each test. after runs the specified block after each test.
  • 20. Expectations //Jasmine it (“should return the sum”, function(){ calc = new Calculator(); expect(calc.Add(4,5).toEqual(9)); expect(calc.Add(4,4).not.toEqual(9)); });
  • 22. Specs - variables Spec - describe('panda',function(){ it('is happy',function(){ expect(panda).toBe('happy'); }); }); JavaScript panda = “happy”;
  • 23. Specs - variables Spec - describe('panda',function(){ it('is happy',function(){ expect(panda).toBe('happy'); }); }); JavaScript panda = “happy”;
  • 24. Specs - functions Spec describe('Hello World function',function(){ it('just prints a string',function(){ expect(helloWorld()).toEqual("Hello world!"); }); }); JavaScript function helloWorld(){ return "Hello world!"; }
  • 25. Specs –matchers Spec describe('Hello World function',function(){ it('just prints a string',function(){ expect(helloWorld()).toContain("world!"); }); }); JavaScript function helloWorld(){ return "Hello world!"; }
  • 26. Specs –Custom matchers Spec describe('Hello world', function() { beforeEach(function() { this.addMatchers({ toBeDivisibleByTwo: function() { return (this.actual % 2) === 0; } }); }); it('is divisible by 2', function() { expect(guessANumber()).toBeDivisibleByTwo(); }); });
  • 27. Spy • Spy are handy in tracking down the usage of dependent or functions that are being invoked by other functions • Take a scenario, where on the website I would like to wish the user like Hi, Hello along with salutation Mr, Ms, Mrs • Say I have a simple function greet() which returns plain string • Another function which returns the salutation() • spyOn(obj, 'method') • expect(obj.method).toHaveBeenCalled()
  • 28. Spy - usage • spyOn(obj, 'method') • expect(obj.method).toHaveBeenCalled() • expect(obj.method).toHaveBeenCalled(“Hello”,”Mr”) • obj.method.callCount
  • 29. Specs – Spy describe("User", function() { it("calls the salutation function", function() { var visitor = new User(); spyOn(visitor, "greetUser"); visitor.greetUser("Hello"); expect(visitor.greetUser).toHaveBeenCalled(); }); });
  • 30. Specs – Functions User = function(){}; User.prototype.greetUser = function(salutation){ return this.sayHello() + "" + salutation; } User.prototype.sayHello = function(){ return "Hello"; }
  • 31. DEMO
  • 32. What next? • Spies • Mocking/Faking • coffee-script • jasmine-jquery • jasmine-fixture • jasmine-stealth