On Tue, Oct 9, 2012 at 8:39 PM, Boris Zbarsky <bzbar...@mit.edu> wrote:

> On 10/9/12 6:46 PM, Jonas Sicking wrote:
>
>> On Tue, Oct 9, 2012 at 2:43 AM, Aryeh Gregor <a...@aryeh.name> wrote:
>>
>>> If it's a pain to write a particular file in testharness.js, it can be
>>> kept as mochitest.  In my experience, quite a lot of tests boil down
>>> to like ten lines, which would take about three minutes more to write
>>> using testharness.js than mochitest.  Also, a test that's based on
>>> testharness.js but uses some Gecko-only features would be easier to
>>> make portable later than a test that's based on mochitest and also
>>> uses Gecko-only features.
>>>
>>
>> This doesn't match my experience at all. My experience is that writing
>> tests has a high cost and results in fairly complex test files.
>>
>
> You're both right.
>
> Simple tests for really basic DOM stuff are very short.
>
> Tests for things like XHR and events and IndexedDB, which are a lot of
> what Jonas has had to write tests for are complete hell to write, if
> nothing else because of the async nature of those objects.
>
> We need a test harness that can handle both use cases without exploding.
>  It's not quite clear to me that testharness.js is it, fwiw.


I'm a little confused, because I looked at testharness.js and thought it
looked perfectly fine, not particularly more or less complex than
SimpleTest/MochiTest.

Here's how I think you'd write a simple XHR test in both:

// SimpleTest aka MochiTest
req = new XMLHttpRequest();
req.open("GET", "/example.json");
req.onreadystatechange = function () {
  if (req.readyState != 4) {
    return;
  }
  is(req.status, 200);
  is(req.getResponseHeader("Content-Type"), "json");
  SimpleTest.finish();
};
SimpleTest.waitForExplicitFinish();


// testharness
var t = async_test("Test XHR");
req = new XMLHttpRequest();
req.open("GET", "/example.json");
req.onreadystatechange = function () {
  if (req.readyState != 4) {
    return;
  }
  t.step(function () {
    assert_equals(req.status, 200);
    assert_equals(req.getResponseHeader("Content-Type"), "json");
  });
  t.done();
};

Am I missing an important difference?  Seems like testharness.js just wants
to add the concept of multiple tests on a page that can independently pass
or fail, and needs just a little more complexity as a result.  But it
doesn't feel like a big deal.

(An aside from the topic of reusable tests, but I feel I should plug an
entirely different testing framework I've written: http://doctestjs.org –
which I think is especially good for spec testing, encouraging really
thorough testing and it makes test writing easy, including async tests.)
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to