qUnit test page result and aggregration?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

qUnit test page result and aggregration?

Post by josh »

I'm getting into qunit for javascript testing. One thing I notice right away is these guys don't seem to believe in defect localization. The test *methods* usually will have like 20+ assertions (each assertion should be it's own test IMO).

So essentially their test *methods* are really actually test *suites* or fixtures in disguise.

But I would consider the fixture to be the HTML at the bottom of the qUnit page. If you look at it this way then your entire test harness uses the same monolithic fixture. you can see this is how the jquery test suite was done.

Efforts have been made by jsUnit and they have an impressive demo showing a plethora of pages being loaded and tested which is very sexy. But that also has its short comings
Under most platform/browser combinations, Test Functions are "auto-discovered" - that is, JsUnit can scan the Test Page and discover what Test Functions are present. For Mac 0S9 with IE5, Mac OSX with IE5, KDE with Netscape 6.x/Mozilla 0.9 and KDE with Konqueror, however, auto-discovery is not supported. You must expose the Test Function names using the exposeTestFunctionNames() function. This function must return a string array of all the Test Functions in the page.
Plus qunit is so much less verbose. So basically I'd like to keep using it, but it is not clear how I should organize my tests.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: qUnit test page result and aggregration?

Post by josh »

I sat down tonight and read thru jsUnit.... wow, much more robust then qunit.

Basically each page gets loaded in order, one after the other. Which is exactly what I want (since my "ajax" would couple the tests otherwise)

Code: Select all

 
JsUnitTestManager.prototype._runTest = function () {
    if (this._testIndex + 1 > this._numberOfTestsInPage) {
        // execute tearDownPage *synchronously*
        // (unlike setUpPage which is asynchronous)
        if (typeof this.testFrame.tearDownPage == 'function') {
            this.testFrame.tearDownPage();
        }
 
        this._currentTestPage.running = false;
        this._currentTestPage.notify(JsUnit.TestPage.STATUS_CHANGE_EVENT);
 
        this._nextPage();
        return;
    }
 
//snip
 
JsUnitTestManager.prototype.loadPage = function (testPage) {
    this._currentTestPage = testPage;
    this._loadAttemptStartTime = new Date();
    this.setStatus('Opening Test Page "' + this._currentTestPage.url + '"');
    this.containerController.setTestPage(this._currentTestPage.url);
    this._callBackWhenPageIsLoaded();
}
They did it exactly how I needed it. Also the fact jsunit has it's own tests, unlike qunit, is going to sway my decision. Even though it looks like it's test method discovery mechanism is cumbersome.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: qUnit test page result and aggregration?

Post by josh »

JsUnit ended up having no support for asynchronous tests. I ended up hacking up a "test page runner" for qunit.
http://joshribakoff.com/?p=173
Post Reply