[Sugar-devel] HTML Sugar: Unit testing research

Manuel Quiñones manuq at laptop.org
Mon May 20 19:47:35 EDT 2013


Now that Daniel N has Jasmine working, let's put it under question :)  Kidding.

In brief: I think Jasmine framework and Karma runner is a simple
enough choice, and just what we need at the moment.

First, here are some concepts:

- BDD - behaviour-driven development.  The usual interface has this
verbs: describe(), it(), before(), after(), beforeEach(), and
afterEach().  This is Jasmine API.

- TDD - test-driven development.  The usual interface has: suite(),
test(), setup(), and teardown().  This is QUnit-like API.

The difference is mostly a question of style.  A BDD expectation is
just a TDD assertion that can be either true or false.  A unit test
can be translated from one style to the other.

- Synchronous and asynchronous tests.  Whether the tool supports
testing asynchronous operations.

I gave a try to Intern http://theintern.io/ .  It looks quite
interesting and can do both, BDD and TDD, and async.  But 1. is too
new (released a few days ago) and 2. unless we want continuous
integration support (CI) or Selenium support, we don't need it.  The
BDD tests in Intern uses Jasmine syntax, so it would be easy to move
in the future, if we ever need to.  By the way, their blog post was
interesting to identify the features a JS testing framework could
have, and the current situation.

http://www.sitepen.com/blog/2013/05/01/intern-javascript-testing/

Mocha is at the same level as Jasmine
http://visionmedia.github.io/mocha/ .  Mocha looks more flexible, but
it adds complexity too.  For example, you have to choose an assertion
library like should.js [1] or chai [2] .

[1] http://github.com/visionmedia/should.js
[2] http://chaijs.com/

One point to Mocha is the asynchronous support.  It is more easy to
write an async test in Mocha than in Jasmine.

http://visionmedia.github.io/mocha/#asynchronous-code

In this boiling Javascript world many things are driven by
mommentum/fashion.  And there is a feeling that Mocha is the current
framework of choise.  For example, Yeoman switched from Jasmine to
Mocha a few months ago:

https://github.com/yeoman/yeoman/issues/117
https://github.com/yeoman/yeoman/pull/187

So if we were to follow fashion, Mocha would be the one :P .  But I
think the simplistic approach of Jasmine is good enough for us,
specially considering the involvement of new devs.  Jasmine is a bit
more readable and elegant too.  The only thing we should consider is
the async support, if we can go with Jasmine one, or if we need Mocha
one.

http://pivotal.github.io/jasmine/#section-Asynchronous_Support

In case we need to move to Mocha in the future, the BDD style is very
similar, the same verbs are used: describe(), it(), etc.  Only the
assertions need to be changed.  Both are mature and widely adopted.

I need to hurry up with Daniel N :)

--
.. manuq ..


More information about the Sugar-devel mailing list