FoxUnit: Unit Test Framework for Firefox

Wednesday September 28th 2005, 8:25 pm Printer Friendly Version
Filed under:Software Development, Firefox
Posted By: Matt

Once upon a time I had a shortish spell as a Java programmer, using the outstanding Eclipse IDE. One of the things I liked most about it was the JUnit integration. Our project (or rather our customer’s project) was very large and complex, so we had a whole suite of tests that we would run before checking in code. The tests were displayed in a sidebar with a progress bar at the top, which turned red if any tests failed. Each individual test was flagged as well if it failed.

Anyway, I decided that we needed the same thing for AllPeers, but hosted inside Firefox. I couldn’t find anything like it, however, so I had to scratch the itch myself. The result is FoxUnit, my modest attempt to imitate what I liked about Eclipse/JUnit but tailored to the Firefox environment. If a much better implementation of this exists that I didn’t discover, don’t even tell me about it. I’d just start crying.

Disclaimers:

  • This is a first version, and I focused on making it do what we need, not what any given Firefox developer might possibly need. So it’s pretty limited and doubtless laden with bugs. If it hurts you, your machine or someone dear to you, I deny all responsibility. I’m hoping it will evolve over time into something more functional and robust.
  • It only runs on Deer Park. I have no idea if it would run on 1.0 as I was too lazy to test it. If someone wants to try, I certainly won’t object.
  • The setup/teardown stuff doesn’t work that well. I need to fix that soon. Use them at your own risk.
  • The progress bar doesn’t always do what you’d expect, especially when you’re not running all the tests. Also needs to be fixed.
  • You can’t debug scripts in the test suite. I believe (on scant evidence) that it would be possible to make this work, but it’s probably not a trivial effort. Something I plan to do one day.
  • The code itself is kind of spaghettish. I’m planning to reorganize it when I have time.

The basic idea is that you have a project file, which lists all the modules that you want to test. I’ve put a simple sample project file here. Each module is contained in an XML file; once again, there’s an example here. Modules are made up of tests, which are made up of test cases. Only the latter contain actual code, which is Javascript embedded in the XML file.

When you load the project, the entire hierarchy (Project -> Module -> Test -> Test Case) is displayed in the FoxUnit sidebar. Click “Open Project” and browse to your project XML file. I strongly recommend that you download the sample files (make sure they are in the same directory) and try them out before attempting to write your own. Press “Run Tests” to run everything, or right click on any node to run just the tests under that node (i.e. all tests in a module, all test cases in a test, or even just one specific test case). When a test case fails, it gets labeled with the red “FAIL” notice, as do all of its parent nodes, so you can see which modules or tests contain failed test cases even if they are collapsed in the tree view.

Download FoxUnit here

Run it with View/Sidebar/FoxUnit or just press Ctrl-Shift-U.


4 Comments »

  1. Hello,
    I cannot understand how to use your extension for testing the extension. I have an extension where KeywordStorage class is defined in one of the js files.

    I have a testcase that looks like this:

    <run>
    var kws = new KeywordStorage();
    </run>

    The test fails, but I cannot see the error message. I have all debugging options turned on, but not a single message appears in the error console while running the test.

    Eugene

    Comment by Eugene Morozov — 10/19/2006 @ 1:09 pm

  2. Any new progress on this? Or compatibility w/FF 2

    Comment by Jeremy Cowles — 9/18/2007 @ 6:23 pm

  3. I couldn’t install it as it is not compatible with 2.0.11 :(

    Comment by Sid — 12/14/2007 @ 5:35 am

  4. This isn’t compatible with FF2 and I have no plans to make it so, but if anyone wants to pick up the ball and run with it, they’re welcome to.

    Comment by Matt — 12/14/2007 @ 9:52 am

Trackback URL RSS feed for comments on this post. TrackBack URI

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

(required)

(required)


 

AllPeers File Sharing



AddThis Feed Button



Creative Commons License
This work is licensed under a Creative Commons License
Conestoga Street Wordpress Theme by Theron Parlin