Thursday, December 18th, 2008

FireUnit: JavaScript Unit Testing Extension

Category: Debugging, Firefox

John Resig and Jan Odvarko have announced something pretty darn cool, FireUnit.

FireUnit provides a simple JavaScript API for doing simple test logging and viewing within a new tab of Firebug.

The example given shows the API nicely:

javascript

  1. // Simple true-like/false-like testing
  2. fireunit.ok( true, "I'm going to pass!" );
  3. fireunit.ok( false, "I'm going to fail!" );
  4.  
  5. // Compare two strings - shows a diff of the
  6. // results if they're different
  7. fireunit.compare(
  8.   "The lazy fox jumped over the log.",
  9.   "The lazy brown fox jumped the log.",
  10.   "Are these two strings the same?"
  11. );
  12.  
  13. // Compare a string using a regular expression
  14. fireunit.reCompare(
  15.   /The .* fox jumped the log./,
  16.   "The lazy brown fox jumped the log.",
  17.   "Compare a string using a RegExp."
  18. );
  19.  
  20. // Display the total results
  21. fireunit.testDone();
  22.  
  23. // -- browser events
  24.  
  25. // You can also simulate browser events
  26. var input = document.getElementsByTagName("input")[0];
  27. fireunit.mouseDown( input );
  28. fireunit.click( input );
  29. fireunit.focus( input );
  30. fireunit.key( input, "a" );
  31.  
  32. // -- Run batches
  33.  
  34. // Or run multiple pages of tests:
  35. fireunit.runTests("test2.html", "test3.html");
  36.  
  37. // Place at the end of every test file in order to continue
  38. fireunit.testDone();

Posted by Dion Almaer at 1:57 am
5 Comments

++++-
4.5 rating from 46 votes

5 Comments »

Comments feed TrackBack URI

It would have be really cool if it had extended the console object instead of using a new one. Imagine this thing ported to every browser already implementing “console”. Life would be way easier.

Comment by frenchStudent — December 18, 2008

This broke my firebug. I had to uninstall fire unit to get it back.

Running FF 2.0.0.19, FB: 1.05

Comment by cgishack — December 18, 2008

@cgishack: If you read the text next to the download link you’ll see why.

* Download Latest Extension (Requires Firefox 3+ and Firebug 1.2+)

Comment by tj111 — December 18, 2008

@tj111 Oh yes.. thanks.

Comment by cgishack — December 18, 2008

Looks nice, especially the event firing stuff. I think I will stick with JSSpec for testing my JavaScipt models, but this will be good for testing the DOM dependent views.

Any chance this could be made to work with Firebug lite so we could run our test suite in other browsers?

Comment by ChrisInCambo — December 20, 2008

Leave a comment

You must be logged in to post a comment.