1 / 36

Zero to Testing in JavaScript

Zero to Testing in JavaScript. Basics of testing in JS. About me. Software developer for Xfinity.com Online: thewebivore.com , @ pamasaur Co -organizer of Philadelphia JavaScript Developers Testing fanatic. Agenda. My testing story Writing your first JavaScript test Testing frameworks

leann
Download Presentation

Zero to Testing in JavaScript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Zero to Testing in JavaScript Basics of testing in JS

  2. About me • Software developer for Xfinity.com • Online: thewebivore.com, @pamasaur • Co-organizer of Philadelphia JavaScript Developers • Testing fanatic

  3. Agenda • My testing story • Writing your first JavaScript test • Testing frameworks • Working testing into your workflow

  4. My testing story

  5. My Testing Story • Code Retreat • TDD • Pairing • Throw-away code • Testing at work • Now: test coverage drops break the build

  6. What’s the deal with testing? • When you break it, it breaks! • Secondary line of documentation defense • Design tool

  7. What do you call code without tests? Legacy code.

  8. Testing front-end code • The debt in your /js folder • Front-end code has logic too! If you have logic, you need tests

  9. BDD/TDD • Behavior Driven Development • Test-Driven Development “Write tests to inform how you write your code” • BDD: Describe, it, before, after, beforeEach, afterEach • TDD: Suite, test, setup, teardown

  10. Test Ever vs. Test Never

  11. Writing your first JavaScript test

  12. Writing your first JavaScript test • Setting up your base • Writing the test* • Making it pass* * The order of these is debatable

  13. Jasmine • jasmine.github.io • Download a standalone version on GitHub from pivotal/jasmine • Or use RubyGems for a Ruby environment

  14. Mocha • visionmedia.github.io/mocha • Node! • npm install –g mocha

  15. Anatomy of a test Describe [thing you’re testing] It [does something you expect it to do] Rinse and repeat.

  16. Example test walk-through with Mocha

  17. var assert = require('assert'); describe("An area of my application", function() { it("should know that 2 and 2 is 4", function(){ assert.equal(4, 2+2); }); });

  18. var assert = require('assert'); describe("An area of my application", function() { it("should know that 2 and 2 is 4", function(){ assert.equal(4, 2+2); }); });

  19. var assert = require('assert'); describe("An area of my application", function() { it("should know that 2 and 2 is 4", function(){ assert.equal(4, 2+2); }); });

  20. var assert = require('assert'); describe("An area of my application", function(){ it("should know that 2 and 2 is 4", function(){ assert.equal(4, 2+2); }); });

  21. var assert = require('assert'); describe("An area of my application", function() { it("should know that 2 and 2 is 4", function(){ assert.equal(2+2, 4); }); });

  22. Testing concepts: Unit testing Test your code

  23. Spies, stubs, and mocks • Spy: an object that records its interactions • Stubs: fake objects • Mocks: fake objects with expected behavior Generally, you can SPY on a function, STUB an object, and MOCK a service.

  24. Live coding? Write a test with me!

  25. Testing Tools

  26. Test describers • Jasmine • Mocha • QUnit • node-tap • YUI Test

  27. Assertions • Chai • should.js • Expect.js • better-assert

  28. Spies, stubs, and mocks • Sinon.js • Jest from Facebook

  29. Test runners • Karma • Teaspoon • YUI Yeti

  30. Bringing testing into the fold 3 tips for making testing a regular part of your world

  31. #1: Teach testing • Attend talks like this! • Practice (ex. Code Retreat) • Pair programming

  32. #2: Code coverage • Istanbul • Blanket.js • hrcov (Mozilla) • JSCover

  33. #3: Code review • Quality assurance • Mentoring • Don’t accept without tests!

  34. What’d we learn? • Writing a JavaScript test • Tools in JavaScript for testing • Ways to create a testing culture

  35. Thank you! • Find me online at • @pamasaur • thewebivore.com (blog) • turing.cool (podcast) • bleedingedgepress.com (upcoming book on JS frameworks)

More Related