UPDATE: Fixed the video resolution issue.  Higher resolution (720p) version is available.

After writing my post on unit testing plugins, I’ve been asked a few times about how to do the same for Dynamics CRM 2011 JavaScript web resources.  While I knew it could be done, truth be told, I had never done any significant JavaScript unit test using Visual Studio other than unit testing Script# code using MSTest (the default unit testing framework in Visual Studio).  Sure, I had played around with QUnit.  However, QUnit is one of those JavaScript testing frameworks which requires tests to run within a browser.  What I wanted was an approach which met the following criteria:

  • Integrate with MSTest so:
    • I have one test dashboard for both my plugin & JavaScript unit tests
    • I get as much of the TFS integration goodness I can get
      • Gated check-ins
      • Running tests on a build server
      • Etc.
  • Write and debug my code without having to constantly deploy to a CRM server to test and iterate on my code
  • Mock things like Xrm.Page, web service calls, interaction with the HTML DOM, etc.
  • Integrate with the Developer Toolkit
  • Run tests OUTSIDE of the context of a browser

So I scoured the internet, tried a bunch of things I came across, and finally landed on approach which combines lessons learned from the following resources:

While the catalyst for this video was to demonstrate JavaScript unit testing in the context of Dynamics CRM 2011, the approach can be applied to any scenario where you are using JavaScript and some additional API (SharePoint, standard web app, etc.).

Just like with my post on unit testing plugins, it is not my goal here to convince you that you should embrace unit testing.  It’s for those of you who have already bought into the value of unit testing, want to apply it to JavaScript web resource development, and do it in a way that meets my stated criteria above.  In the video, I assume you understand concepts like mocks, fakes, etc. 

You can grab the finished example I show in the walkthrough here:

http://sdrv.ms/StxcgU

Hope this helps those of you who have been as eager as I have to unit test JavaScript web resources.

@devkeydet