10
Jasmine Unit testing with

Unit testing with Jasmine

Embed Size (px)

Citation preview

Page 1: Unit testing with Jasmine

JasmineUnit testing with

Page 2: Unit testing with Jasmine

Why unit test?

Your probably already doing it (debugging)

Prevents regression/allows REFACTORING

Fastest form of quality feedback Allows you to work on other peoples

code Improves the design of your code Is a form of living documentation

Page 3: Unit testing with Jasmine

What is a unit?

“The smallest testable part of an application” JavaScript public function === unit

Utility Code Functional Code

Page 4: Unit testing with Jasmine

How to unit test?

Practical

Page 5: Unit testing with Jasmine

The good

TDD – test driven development Write a test Run it (it’s red) Write some code Run it (it goes green) Repeat.

Page 6: Unit testing with Jasmine

The bad

Testing after the fact Boring Harder to write test code Tightly coupled test code Miss ‘conceptual’ errors

Page 7: Unit testing with Jasmine

The practical

Test during development New features ? Test driven development Bug fixes ? write tests for the unit Before refactor ? write tests before &

modify

Page 8: Unit testing with Jasmine

End game

Comprehensive suite of tests for your app

Test lines ratio to code @3 : 1 Run on every commit by CI ‘Stop the line’ when a test fails

Page 9: Unit testing with Jasmine

Jasmine Overview

Behavior driven development (bdd) describe(”your module", function() {

it(”should be unit tested", function() { expect(isUnitTested()).toBe(true); });

});

Page 10: Unit testing with Jasmine

Live Demo!