Quantcast
Viewing all articles
Browse latest Browse all 68

It Takes a Lot of Chutzpah to Run QUnit and Jamsine Unit Tests in Visual Studio

It’s never easy to unit test your code well, but to unit test your JavaScript code in Visual Studio takes Chutzpah. And I don’t mean it takes audacity in the classic Yiddish sense of the word, either. I mean it requires a Visual Studio extension called Chutzpah which can help you automate running your Jasmine, QUnit, or Mocha unit tests for your ASP.NET projects in Visual Studio. Chutzpah supports the two most recent versions of Visual Studio–VS 2012 and VS 2013–and it works with all types of ASP.NET projects. It’s really very simple to install. You can use the Extensions and Updates… option from the Tools menu or download and run the .VSIX file from its entry on the Visual Studio gallery site.

Image may be NSFW.
Clik here to view.
2014-09-29 14_40_28-

To install it from the Extensions and Updates window, simply search online for Chutzpah and click the Install button. Once you have the extension installed, getting it seat up to run your unit tests is also very easy. Open the Test Explorer window (Test > Window > Test Explorer) and you will see all of your project’s QUnit, Jasmine, or Mocha unit tests listed. Click Run All to run the unit tests manually, or toggle on Test > Test Settings > Run Tests After Build to have them run by Visual Studio automatically whenever it does a build.

Image may be NSFW.
Clik here to view.
2014-09-29 15_46_00-WebApplication19 - Microsoft Visual Studio

Here’s a simple example. If I have the following JavaScript module defined in /app/app.js:

window.app = (function () {

    return {
        addNumbers: function (a, b) {
            return a + b;
        }
    };

})();

I can now create the following QUnit unit test in /tests/test.js:

/// <reference path="../app/app.js" />

test("adding 1 + 2", function () {
    var result = window.app.addNumbers(1, 2);
    ok(result === 3, "should be 3");
});

Notice that the app.js file is referenced via a comment that appears at the top of the file. This loads app.js before running the tests in this file. With this setup work complete, I now see the test listed in my Visual Studio Test Explorer.

Image may be NSFW.
Clik here to view.
2014-09-29 15_51_29-WebApplication19 - Microsoft Visual Studio

More information at the following links:

The post It Takes a Lot of Chutzpah to Run QUnit and Jamsine Unit Tests in Visual Studio appeared first on Falafel Software Blog.


Viewing all articles
Browse latest Browse all 68

Trending Articles