Tags

, ,

Karma or Protractor

Karma is a JavaScript test-runner built with Node.js, and meant for unit testing.

Protractor is for end-to-end testing, and uses Selenium Web Driver to drive tests.

Both have been made by the Angular team. You can use any assertion-library you want with either.

related:

pros:

  • Uses node.js, so compatible with Win/OS X/Linux
  • Run tests from browser or headless with PhantomJS
  • Run on multiple clients at once
  • Option to launch, capture, and automatically shutdown browsers
  • Option to run server/clients on development computer or separately
  • Run tests from command line (can be integrated in ant/maven)
  • Write tests xUnit or BDD style
  • Supports multiple JavaScript test frameworks
  • Auto-run tests on save
  • Proxies requests cross-domain
  • Possible to customize:
    • Extend it to wrap other test-frameworks (Jasmine, Mocha, QUnit built-in)
    • Your own assertions/refutes
    • Reporters
    • Browser Launchers
  • Plugin for WebStorm
  • Supported by Netbeans IDE

cons:

  • Does not support NodeJS testing
  • No plugin for Eclipse (yet)
  • No history of previous test results

TestSwarm

John Resig (jQuery) has created a tool for distributed JavaScript testing, TestSwarm. Mainly for open source JavaScript projects, but TestSwarm is open source, so you can set up a server yourself for corporate testing. Although this might require that you to do some modifications.

pros:

  • Continuous integration server for JavaScript
  • Supports all major browsers/operating systems
  • Run on multiple clients at once
  • Don’t need to run server/clients on development computer (no need for IE)
  • Automatically run tests on all clients when you commit something (or whenever you modify the script to run the tests)
  • Show history of test results pr commit
  • Supports multiple JavaScript test frameworks
  • Have test results for OS and browser versions
  • Crowd source to test in a multitude of browsers

cons:

  • Cannot break your build through ant/maven
  • Don’t notice the test fail before commit
  • No IDEplug-in

http://ejohn.org/blog/javascript-testing-does-not-scale/

Jasmine

This is a client-side test-runner that might interest developers familiar with Ruby or Ruby on Rails. The syntax is based on RSpec that’s used for testing in Rails projects.

Jasmine is a behavior-driven development framework for testing your JavaScript code. It does not depend on any other JavaScript frameworks. It does not require a DOM.

Project home: http://jasmine.github.io/

 QUnit

QUnit is a powerful, easy-to-use JavaScript unit test suite. It’s used by the jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript code

QUnit shares some history with TestSwarm (above):

QUnit was originally developed by John Resig as part of jQuery. In 2008 it got its own home, name and API documentation, allowing others to use it for their unit testing as well. At the time it still depended on jQuery. A rewrite in 2009 fixed that, now QUnit runs completely standalone. QUnit’s assertion methods follow the CommonJS Unit Testing specification, which was to some degree influenced by QUnit.

Project home: http://qunitjs.com/

mocha.js

I’m totally unqualified to comment on mocha.js’s features, strengths, and weaknesses, but it was just recommended to me by someone I trust in the JS community.

List of features, as reported by its web site:

  • browser support
  • simple async support, including promises
  • test coverage reporting
  • string diff support
  • javascript API for running tests
  • proper exit status for CI support etc
  • auto-detects and disables coloring for non-ttys
  • maps uncaught exceptions to the correct test case
  • async test timeout support
  • test-specific timeouts
  • growl notification support
  • reports test durations
  • highlights slow tests
  • file watcher support
  • global variable leak detection
  • optionally run tests that match a regexp
  • auto-exit to prevent “hanging” with an active loop
  • easily meta-generate suites & test-cases
  • opts file support
  • clickable suite titles to filter test execution
  • node debugger support
  • detects multiple calls to done()
  • use any assertion library you want
  • extensible reporting, bundled with 9+ reporters
  • extensible test DSLs or “interfaces”
  • before, after, before each, after each hooks
  • arbitrary transpiler support (coffee-script etc)

All the best 🙂

Advertisements