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

Like this? Share it with your network

Share

Jasmine - A BDD test framework for JavaScript

  • 1,314 views
Uploaded on

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.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,314
On Slideshare
1,069
From Embeds
245
Number of Embeds
15

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 245

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

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. TDD – BDD - Jasmine
  • 2. Agenda• Introducing TDD• Steps to BDD• Familiarize terminology• Installation• Executing jasmine• Write tests in jasmine• What next?
  • 3. 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
  • 4. 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
  • 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 issignificantly more important!”• It’s all behavior
  • 6. BDD• Behaviour Driven Development is an Agiledevelopment process that comprises aspects of– Acceptance Test Driven Planning,– Domain Driven Design– Test Driven Development
  • 7. BDD• BDD puts the focus on Behavior rather thanstructure• 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) insoftware development we narrate/describe thelogical chunks as scenarios• Given/When/Then – called as BDD triad
  • 9. BDD Cycle
  • 10. Jasmine
  • 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, asMaven 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 buildsystems
  • 14. Terminology•Specs•Suites•describe•it•expect•matchers•mocks•spies
  • 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
  • 17. http://try-jasmine.heroku.com/
  • 18. 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(){----------};});});
  • 19. 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.
  • 20. 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));});
  • 21. http://try-jasmine.heroku.com/
  • 22. DEMO
  • 23. Specs - variablesSpec -describe(panda,function(){it(is happy,function(){expect(panda).toBe(happy);});});JavaScriptpanda = “happy”;
  • 24. Specs - functionsSpecdescribe(Hello World function,function(){it(just prints a string,function(){expect(helloWorld()).toEqual("Hello world!");});});JavaScriptfunction helloWorld(){return "Hello world!";}
  • 25. Specs –matchersSpecdescribe(Hello World function,function(){it(just prints a string,function(){expect(helloWorld()).toContain("world!");});});JavaScriptfunction helloWorld(){return "Hello world!";}
  • 26. DEMO
  • 27. What next?• Spies• Mocking/Faking• coffee-script• jasmine-jquery• jasmine-fixture• jasmine-stealth
  • 28. DEMO
  • 29. 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
  • 30. Follow Traffic Ruleshttp://trupil.blogspot.in/2010/10/traffic-rules-follow-it.html