[Warning]: I am new to the whole unit testing and have been trying to learn as much as possible.

I am working on a MS CRM 2011 project and I have been trying to introduce unit testing in my company. For unit testing JavaScript web resources, I found this link at MSDN blog.

The Solutions Architect in my company suggest that this is a bad approach as we are not even testing against the IE's JS engine but testing using CScript (Windows Host) and while I agree to that point, isn't the whole idea of Unit Testing all about testing the individual function's functionality and not about the dependency.

For testing whether it will work within IE, would a testing tool such as Selenium not be better?

Or am I missing something?


According to Wikipedia, "JScript" in IE is based on the same scripting engine as JScript in Windows Scripting Host. So generally, the approach to use the WSH / CScript for unit testing of JScript functions targeting at IE is fine. You should, however, make sure that the IE version (or the JS version which is supported in the related IE versions) matches the WSH version you are using for your tests.

In fact, what you indeed cannot test by the CScript approach is how your code behaves within the browser, especially when you have functions using the rendering engine of the IE, or which are relying on browser events. For those parts of your code, a browser automation tool like Selenium maybe more appropriate. However, with Selenium you are typically creating automated integration tests, not unit tests.

For a good test suite, you probably need both - unit tests for browser-independent functions and (automated) integration tests for browser-dependent functions. So it should not be a decision of "either this or that", use both, and each tool for the specific kind of test.


If you need to Unit Test in the browser, I wholly recommend you look at Karma. You can run your test simultaneously on any number of browsers, on any number of devices.

And your architect is right : you must test in the correct runtime. Otherwise, you may end up using something that does not work correctly on a supported browser ( for example Array#map which does not work on IE8 ). The same way you should run .NET4.0 unit tests in a .NET4.0 runtime. With JavaScript, especially with older IEs, assume that even basic stuff can break and should be tested.

If your looking for a good tutorial for unit testing JavaScript, you may want to look at James Shore JavaScript TDD. It really explain not only how to do Unit Test, but also how to do a proper test driven development and how to structure your application and development for tests. Its a bit biaised toward node.js but you can skip the server part. First week is free! If you're new to unit test you will probably learn a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.