Tobie Langel of Prototype fame has created another unit testing library for JavaScript. Another one I hear you say? Well, if Tobie did it.... it is worth checking out. Time to get some Evidence.

I found out about it over dinner in Berlin at the great JSConf.EU. At the table were 6 people from 6 different countries. Go JavaScript diversity :) I first asked "BDD?" and Tobie spat out "No, I friggin hate BDD, especially for JS" before I had even finished the question.

Tobie gave a talk on Evidence at the show, and explained the focus of the library:

  • Library agnostic (the scripty based one in Prototype was based on Prototype which is weird when you test yourself)
  • Environment agnostic (e.g. not just in the browser)
  • Self contained (no global pollution)
  • Built with async in mind (in JS / client server / anything real, you gotta do async)
  • Easy to automate
JAVASCRIPT:
  1.  
  2. Evidence.TestCase.extend('ArrayTest', {
  3.   setUp: function() {
  4.     this.array = ['foo', 'bar', 'baz'];
  5.   },
  6.  
  7.   testFirst: function() {
  8.     this.assertEqual('foo', _.first(this.array));
  9.     this.assertUndefined(_.first([]));
  10.   },
  11.  
  12.   testLast: function() {
  13.     this.assertEqual('bar', _.last(this.array),
  14.       'Failed to grab the last element of the array.');
  15.     this.assertUndefined(_.last([]));
  16.   }
  17. });
  18.  

Related News :