To test or not to test? This shouldn’t be the question. When, where and how; that’s something open for discussion, but testing is close to mandatory nowadays. Even more so in a continuous delivery environment where changes get in production, or in the hands of the users, quicker and quicker by each passing day.
Step 1. Install Chutzpah
I installed the Chutzpah NuGet to my project using the Package Manager Console.
I found out it's useful to install both extensions 'Chutzpah Test Adapter for the Test Explorer' and 'Chutzpah Test Runner Context Menu Extention' offered by Chutzpah, from the Visual Studio Extensions browser.
The second extension is a context menu extension that allows us to run the tests with only two mouse clicks. This plugin also provides additional functionality such as code coverage results and debugging which can be done directly from Visual Studio.
Step 2. Install Jasmine
Step 3. Configure Chutzpah
Here is a sample of my Solution where all of this was tested:
Then in the Tests folder, the unit test, calculator.tests.js, written using Jasmine.
You can also see the chutzpah.json file that I added manually. Here I am telling Chutzpah that the testing framework I use is Jasmine, where it can find the necessary references and the path to my tests.
Though I only used these three properties (Framework, References and Tests), the chutzpah.json file supports a lot more properties that can be used to properly configure the way Chutzpah handles your solution and tests.
Step 4. Run
Because I already installed the Test Adapter, the tests are now available in the test explorer. Chutzpah actually contains PhantomJS as a dependency, so running the tests from Test Explorer will do so in a headless way.
Step 5. Debug (if needed)
As I already said, the second extension I installed allows us to debug the tests. Just right click the test and select Run Chutzpah with Debugger. This will actually start your browser and get Visual Studio in debug mode.
Step 6. Add a “Test” task
Step 7. Configure the “Test” task
Then I make sure that I point to the Chutzpah test adapter, the NuGet package that I installed earlier. In my case this path was $(Build.SourcesDirectory)\packages.
And that should be it. Now all is left to do is queue a new build and check that the tests are executed accordingly.