开发者

How do I unit test JavaScript using nUnit?

I would like to run unit tests of my JavaScript code in Cruise Control. W开发者_Python百科e currently use nUnit, and I see that nUnit has a javascript library. How do I write unit (not UI) tests in JavaScript using nUnit?


The best way to automate JS tests and include them in continuous integration process is to use JSTestDriver. It is very fast, can test your scripts in all kinds of browsers, can be easily integrated in IDE (How To ntegrate JsTestDriver in Visual Studio), and what is more important - this is simple comsole application, which can be easily be executed from nant script.

The example of solution with JsTestDriver tests is here.


You can do this with JSUnit. Their JSUnit Server allows you to run scriptable JavaScript unit tests within a Java virtual machine (JVM).


You can use Rhino, which is a Javascript runtime written in Java (IIRC, the command-line is something like java -jar Rhino.jar script.js). This is especially useful if your tests don't require a browser.

Don't forget to analyze your JS code with JSLint !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜