test driven development in javascript

Post on 11-Feb-2017

193 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Test Driven Development in JavaScriptANURAJ PWWW.DOTNETTHOUGHTS.NET

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

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

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.

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'); });

Demo

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

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>

Demo

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/

Questions ?

top related