1 Mar 2014

Testing JavaScript with Visual Studio

If your web application is using JavaScript for non trivial functionality then it makes sense to test it programmatically. Various JavaScript frameworks have been written to allow you to write JavaScript tests to test your JavaScript.

This pluralsight course gives a good overview: pluralsight - Testing Clientside JavaScript

The main decisions you will need to make

1. What style do you want to write your tests in ?

Behaviour Driven Development (BDD) or Test Driven Development (TDD), as this will influence which JavaScript test framework you use.

 

2. The JavaScript Test framework you are going to use, the most popular are:

3. Which test runner or runners you want to use. The options are:

Outside of Visual Studio:

  • Browser
  • Grunt

Within Visual Studio

  • Visual Studio Extension: Chutzpah 
  • Visual Studio Extension: KarmaVs. (Also requires Node.js)
  • ReSharper 6

My choice is to use a combination of Chutzpah and Browser.

Browser Test Runner

This is the simplest choice, and can be debugged in visual studio, but requires an HTML file for each test / suite of tests.

BrowserJavascriptTesting[4]

Visual Studio Extension - Chutzpah

< p> Chutzpah is a visual studio extension which contains 3 of the most popular testing frameworks (Mocha, Quit, Jasmine). It runs and displays your tests in the test explorer.

The major drawback is that you can't debug tests.

http://chutzpah.codeplex.com/

In Visual studio 2012/2013: Tools->Extensions and Updates -> Online -> Search for 'Chutzpah'. Install:
•Chutzpah Test Runner Context Menu Extension
•Chutzpah Test Adaptor for the Test Explorer

VisualStudioJavaScript[3]

Configuration

Optionally add a Chutzpah.json file, amend to indicate your chosen framework.

Chutzpah.json Settings File

{
    "Framework": "qunit"

    "TestHarnessLocationMode": "TestFileAdjacent",    

    "TypeScriptCodeGenTarget" : "ES5",

    "RootReferencePathMode":"SettingsFileDirectory"

}

blog comments powered by Disqus

Image attribution: "color noise anomalies" by Carlos Lopez de Pablo is licensed under CC BY 2.0

About Me


My first computer was a Commodore VIC-20, I had great fun trying to code text adventures and side scrolling shoot ‘em ups in BASIC. This helped me lead the way as the first in my school to pass a computer exam.

Currently I work as a Senior Software Engineer in Bedford for a FTSE 100 Company. Coding daily in C#, JavaScript and SQL. Outside of work I work on whatever is interesting me at that time.