Chutzpah Test Runner for Jasmine JavaScript tests

30. December 2014 16:43

 

I’ve been using Jasmine to write unit tests for JavaScript code and just using the built in browser test runner to the tests. The phase is to incorporate these tests from a command line, build or from within Visual Studio. Running the tests in the browser is pretty straight forward, you just include the necessary Jasmine scripts along with your unit tests and away you go.

image

image

So, nice. We can run our tests and see that they all pass. Except now the c# tests run in Test Explorer in Visual Studio. And to run the JavaScript tests you have open a browser. Chutzpah to the rescue! You can install Chutzpah via NuGet and run it from a command line (which I’m sure will work great with builds, and I’ll test that out when we get a build server set up). There is also a very cool extension to allow you to run the JavaScript tests in the Visual Studio test Explorer!  This is where I ran into some confusing problems. The tests all run and pass in the browser. But running them in Visual Studio they were failing! Some poking around and googling pointed me to the cause. When the tests run in the browser all of the references (angular, etc.) are added in the html page that hosts the tests. When running them in Visual Studio there is no wrapper and nothing including the referenced libraries. Luckily Chutzpah has an answer and Chutzpah.json is it. Add this file and configure your references in it.

image

Now, like magic your Jasmine JavaScript tests show up right along your c# tests in Test Explorer.

image

About the author

I'm a .NET developer, a husband and a father of three beautiful girls.

Month List