• Save
Jasmine - A BDD test framework for JavaScript
Upcoming SlideShare
Loading in...5
×
 

Jasmine - A BDD test framework for JavaScript

on

  • 1,134 views

Jasmine is the BDD implementation for JavaScript. With it's Behavior Driven approach developers are empowered with more testing capabiliites. ...

Jasmine is the BDD implementation for JavaScript. With it's Behavior Driven approach developers are empowered with more testing capabiliites.

Although BDD is principally an idea about how software development should be managed by both business interests and technical insight, the practice of BDD does assume the use of specialized software tools to support the development process.

Statistics

Views

Total Views
1,134
Views on SlideShare
916
Embed Views
218

Actions

Likes
1
Downloads
0
Comments
0

14 Embeds 218

http://sumanthtechsavvy.blogspot.com 110
http://sumanthtechsavvy.blogspot.in 77
http://sumanthtechsavvy.blogspot.com.br 7
http://sumanthtechsavvy.blogspot.ru 7
http://sumanthtechsavvy.blogspot.ca 4
http://sumanthtechsavvy.blogspot.de 3
http://sumanthtechsavvy.blogspot.fr 2
http://sumanthtechsavvy.blogspot.nl 2
http://sumanthtechsavvy.blogspot.com.ar 1
http://webcache.googleusercontent.com 1
http://sumanthtechsavvy.blogspot.co.uk 1
http://sumanthtechsavvy.blogspot.it 1
http://sumanthtechsavvy.blogspot.ro 1
http://sumanthtechsavvy.blogspot.com.es 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Jasmine - A BDD test framework for JavaScript Jasmine - A BDD test framework for JavaScript Presentation Transcript

  • TDD – BDD - Jasmine
  • Agenda• Introducing TDD• Steps to BDD• Familiarize terminology• Installation• Executing jasmine• Write tests in jasmine• What next?
  • TDD• Involves writing tests before writing the codebeing tested• Write a small test first (at this point of time nocode 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 refactorbecomes critical• Since most of the time the features are not pre-determined reviewing/refactoring does prove astime 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 issignificantly more important!”• It’s all behavior
  • BDD• Behaviour Driven Development is an Agiledevelopment process that comprises aspects of– Acceptance Test Driven Planning,– Domain Driven Design– Test Driven Development
  • BDD• BDD puts the focus on Behavior rather thanstructure• 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) insoftware development we narrate/describe thelogical 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, asMaven 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 buildsystems
  • 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://try-jasmine.heroku.com/
  • describe ... itdescribe accepts astring or class.Helps inorganizing specsit is what describes thespec. It optionallytakes a string// Jasminedescribe “Calculate”, function() {describe “#Add”, function(){it “should give sum”, function(){----------};});});
  • Filters// Jasminevar calc;beforeEach(function(){calc = new Calculator();});afterEach(function(){calc.reset();});Pretty handy to create datafor each testbefore runs the specifiedblock before each test.after runs the specified blockafter each test.
  • Expectations//Jasmineit (“should return the sum”, function(){calc = new Calculator();expect(calc.Add(4,5).toEqual(9));expect(calc.Add(4,4).not.toEqual(9));});
  • http://try-jasmine.heroku.com/
  • DEMO
  • Specs - variablesSpec -describe(panda,function(){it(is happy,function(){expect(panda).toBe(happy);});});JavaScriptpanda = “happy”;
  • Specs - functionsSpecdescribe(Hello World function,function(){it(just prints a string,function(){expect(helloWorld()).toEqual("Hello world!");});});JavaScriptfunction helloWorld(){return "Hello world!";}
  • Specs –matchersSpecdescribe(Hello World function,function(){it(just prints a string,function(){expect(helloWorld()).toContain("world!");});});JavaScriptfunction helloWorld(){return "Hello world!";}
  • DEMO
  • What next?• Spies• Mocking/Faking• coffee-script• jasmine-jquery• jasmine-fixture• jasmine-stealth
  • DEMO
  • ThanksReferences: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/Spiestosumanthkrishna@gmail.com
  • Follow Traffic Ruleshttp://trupil.blogspot.in/2010/10/traffic-rules-follow-it.html