Search code examples
javascriptunit-testingtestingtest-framework

What is a pure in-browser JavaScript test framework?


I want a unit-test framework for JavaScript which runs in the browser. Not with an external browser-automation system as in Selenium, or a non-browser JS environment, but just one .html which loads the test framework and test suite and displays the results in that page. My searches have found only the other two kinds.

I am primarily interested in testing JavaScript code for expected results and not crashing, not DOM/events or visual appearance.

Nice-to-haves:

  • Performance testing/benchmarking as well as correctness testing.
  • Optional external automation so a shell command can run the test suite and check if it succeeded.

The motivation for the requirements is:

  • My application under test is currently itself pure JavaScript, and I'd like to keep it that way (without platform or other-language dependencies).
  • I am using many newer or bleeding-edge features such as ECMAScript 5, Typed Arrays, WebGL, and Local Storage. I want to test the actual interaction with these facilities, not stubs.

Solution

  • jsunit or Jasmine

    You can run Selenium in the browser only. Download Selenium Core 1.01. Upload the unzipped files to the domain you want to test. Open /core/TestRunner.html and start the browser only frontend of Selenium :)

    I use this kind of test in several projects. It's perfect to have only one place to store and to run tests. You can trigger those these by cronjobs and capture the results as well. I extended it a lot and I save the results to a Database and take automatically screenshots with JS when errors occur.

    If this kind of running Selenium is still supported in version > 2.0, I don't know. Here is a tiny documentation.