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:
- QUnit(TDD) qunitjs.com
- Jasmine(BDD) pivotal.github.io/jasmine
- Mocha (TDD or BDD). visionmedia.github.io/mocha
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.
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.
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
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"
}