, , , ,

The time has come to retire NQUnit. NQUnit runs QUnit tests inside .NET by using WatiN. That means it can be used with any test runner supporting NUnit (e.g. TestDriven.NET or – since VS2012 – built-in + adapter). If you use CI server to run NUnit you got JavaScript tests nicely integrated for free (well, almost).

Unfortunately, there are some flaws:

  • tests are run in the full browser – which is slow
  • the only available browser option is Internet Explorer (on our CI server it can’t be upgraded beyond v8)
  • the are some privileges problems described in one of my previous posts
  • it requires some boilerplate C# code, which – of course – need to be compiled
  • tests can’t be run selectively
  • doesn’t play nice with continuous testing tools like NCrunch
  • supports only QUnit and only tests wrapped with HTML (forget about bare JavaScript tests or other frameworks e.g. Jasmine or Mocha)

NuGet Gallery showed me several candidates of whom I’ve chosen Chutzpah and so far I’m not disappointed. Chutzpah supports both the QUnit and Jasmine. Uses the PhantomJS headless browser to run tests. Not only JavaScript but also TypeScript and CoffeeScript are supported.

Chutzpah consists of 3 components:


  1. How to execute HTML wrapped QUnit tests:

    > chutzpah.console.exe /testMode Html /file AwesomeWidgetTest.html

  2. How to run all tests in a folder:

    > chutzpah.console.exe /testMode Html /path .\Facts\JS\

Parameter testMode is optional. Other values are: All (default), Html, AllExceptHTML, TypeScript, CoffeeScript, JavaScript. For more info see docs.

CI server support

Chutzpah support TeamCity OOTB. For other servers there is /junit switch that output results to JUnit-style XML file. I’ve used it for our CruiseControl.NET server. My MSBuild target looks as follows:

<Target Name="RunJavaScriptTests">
  <CreateItem Include="**\QUnit\*Test.html;**\Jasmine\*Test.js">
    <Output ItemName="JsTests" TaskParameter="Include" />
  <Exec Command="&quot;$(ChutzpahPath)&quot; /file &quot;%(JsTests.FullPath)&quot; /junit &quot;$(NUnitLogsDir)\%(JsTests.FileName)-test-results.xml&quot;" />

PS Today’s Chutzpah 2.4 release brings code coverage (via BlanketJS) and contains my tiny patch for unicode support :).