Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Stephen Walther on Integrating JavaScript Unit Tests

Stephen Walther on Integrating JavaScript Unit Tests

This item in japanese


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.

Rate this Article


Hello stranger!

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

Get the most out of the InfoQ experience.

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

Community comments

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

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