2008年10月6日月曜日

JavaScript Unit Testing Frameworks

JavaScirpt の Unit Testing フレームワークを調査してみました。
調査してみると想像以上に、大変沢山あることが分かりました。。

全てを比較している暇はないので、選定基準を設け、有望そうなものをピックアックすることにしました。選定基準は以下のようになります。
  • Intuitive, simple, but enough API support.
  • Easy to introduce.
    • If possible, we don't want to introduce any other run time.
  • Ajax testing support (if possible)
  • Enough matured or active community supports
  • It's more better if the framework have a good compatibility with jQuery.
  • It may be useful also if the frameworks can be scripted, or at least callable fro CLI.
この元では、以下の 3 つが有望そうな JavaScript Unit Testing フレームワークとなります。これらの特徴及び、長所、短所を整理すると以下のようになります。(英語ですみません。。)
  • JsUnit
    • Feature:
      JsUnit is a Unit Testing framework for client-side (in-browser) JavaScript.
      It is essentially a port of JUnit to JavaScript.
      Also included is a platform for automating the execution of tests on multiple browsers and mutiple machines running different OSs.
      This goes a long way to addressing the old problem of inconsistency in JavaScript implementations across browsers.

    • Pros: Very matuared. (Its development began in January 2001.

    • Cons: Now thier community is less active than other frameworks'. (JavaScript and the browser is changing rapidly now, so it's a critical problem.)

  • YUI Test
    • Feature:
      Yahoo User Interface Test: YUI Test is a testing framework for browser-based JavaScript solutions.
      Using YUI Test, you can easily add unit testing to your JavaScript solutions.YUI Test features:

      • Rapid creation of test cases through simple syntax.
      • Advanced failure detection for methods that throw errors.
      • Grouping of related test cases using test suites.
      • Asynchronous tests for testing events and Ajax communication.
      • DOM Event simulation in all A-grade browsers.

    • Pros:
      • YUI Test does derive some characteristics from nUnit and JUnit.
      • Ajax support officialy.
      • Many Documents

    • Cons:
      • Not OSS.
      • Not a direct port from any specific xUnit framework.
      • Althogh this script may have good compatibility with YUI, it's not certain that it also have it with jQuery.

  • QUnit
    • Feature:
      QUnit is the unit testrunner for the jQuery project.
      It got promoted to a top-level project in May 2008 to make it easier to use in other projects, with focus on jQuery UI.
      It's especially useful for regression testing

    • Pros:
      • The community is very active.
      • It must be good compatible with jQuery.

    • Cons: This project started just only month ago.(This script have been being used for jQuery itself since the jQuery project started, though.)