BT

Stephen Walther on Integrating JavaScript Unit Tests

by Jonathan Allen on Jan 19, 2011 |

In order to be considered suitable for automated testing, a unit testing framework needs to meet two important criteria. The first is of course the quality of the libraries with which you will build the tests themselves. The second criterion is that it integrates with your tool chain. For .NET developers, that means being able to run JavaScript tests inside your IDE and via your builds scripts. While most frameworks have focused exclusively on the former, Stephen Walther has been working on a solution to the second.

Stephen Walther’s full design can be seen in his post titled Integrating JavaScript Unit Tests with Visual Studio, so we are just going to hit the highlights.

The most important thing is that there is no browser component in his design. This has some interesting ramifications.

  • Since you don’t have to spin up browsers, the tests runs are naturally fast.
  • Likewise the environment is pure. Only the code you explicitly import into the test engine is in scope, nothing from the browser can leak in.
  • Since it is a clean, browserless environment you don’t have access to the DOM or other web-specific objects.
  • While perfect for pure JavaScript libraries, this is completely inappropriate for UI testing. (This could change with a heavy investment in mocking the web-specific objects.)

While any independent JavaScript engine would work for his purposes, Stephen has chosen the JScript engine shared by IE, Windows Script Host, and classic ASP. This has the advantage of being exposed to .NET both via the Windows Script Interfaces and the Microsoft Script Control.

From there he built a very primitive JavaScript testing library that bridges the gap between the JScript engine and the MSTest framework. Considering the simplicity of his design, this technique can be used to marry practically any combination of JavaScript testing library, JavaScript engines, and automated testing frameworks.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT