test driven development in javascript

11
Test Driven Development in JavaScript ANURAJ P WWW.DOTNETTHOUGHTS.NET

Upload: anuraj-p

Post on 11-Feb-2017

193 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Test driven development in JavaScript

Test Driven Development in JavaScriptANURAJ PWWW.DOTNETTHOUGHTS.NET

Page 2: Test driven development in JavaScript

Agenda 1. What is Test Driven Development (TDD)

2. Tools / Framework for TDD in JavaScript

3. Demo

4. Code Coverage

5. Tools / Framework for Code coverage in JavaScript

6. Demo

7. JavaScript TDD with Visual Studio

8. Questions

Page 3: Test driven development in JavaScript

What is Test Driven Development (TDD)

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards. Kent Beck, who is credited with having developed or 'rediscovered' the technique, stated in 2003 that TDD encourages simple designs and inspires confidence.

Test-driven development is related to the test-first programming concepts of extreme programming, begun in 1999, but more recently has created more general interest in its own right. – Source - Wikipedia

Page 4: Test driven development in JavaScript

What is Test Driven Development (TDD)

Here is fundamental mantra of TDD:

Write a test and make it fail.

Make the test pass.

Refactor.

Repeat.

This technique also referred as “Red-Green-Refactor” because IDE’s and test runners use red color to indicate failed tests and green color to indicate the tests that passed.

Page 5: Test driven development in JavaScript

Tools / Framework for TDD in JavaScript

QUnit

QUnit is a powerful, easy-to-use JavaScript unit testing framework. It's used by the jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript code.

https://qunitjs.com/

A minimal JavaScript test

test("testname", function() { assert(expression, 'Message'); });

Page 6: Test driven development in JavaScript

Demo

Page 7: Test driven development in JavaScript

Code Coverage In computer science, code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite. A program with high code coverage has been more thoroughly tested and has a lower chance of containing software bugs than a program with low code coverage. – Source – Wikipedia

Page 8: Test driven development in JavaScript

Tools / Framework for Code coverage

Blanket.js

Blanket.js is an easy to install, easy to configure, and easy to use JavaScript code coverage library that works both in-browser and with nodejs.

Enable code coverage using blanket.js

<script type="text/javascript" src="./scripts/mathlib.js" data-cover></script>

Page 9: Test driven development in JavaScript

Demo

Page 10: Test driven development in JavaScript

JavaScript TDD with Visual Studio

Chutzpah - A JavaScript Test Runner

Chutzpah is an open source JavaScript test runner which enables you to run unit tests using QUnit, Jasmine, Mocha, CoffeeScript and TypeScript.

https://chutzpah.codeplex.com/

Page 11: Test driven development in JavaScript

Questions ?