Dojo Objective Harness (DOH)
Automated testing practices for web applications are becoming increasingly common because of the sheer amount of coding and complexity involved in many of today's rich Internet applications. DOH uses Dojo internally but is not a Dojo-specific tool; like ShrinkSafe, you could use it to create unit tests for any JavaScript scripts, although no DOM manipulation or browser-specific functions will be available.
DOH provides three simple assertion constructs that go a long
way toward automating your tests. Each of these assertions is provided
via the global object, doh, exposed
by the framework:
doh.assertEqual(expected, actual)doh.assertTrue(condition)doh.assertFalse(condition)
Before diving into some of the more complex things that you can do with DOH, take a look at trivial test harness that you can run from the command line via Rhino to get a better idea of exactly the kinds of things you could be doing with DOH. The harness below demonstrates the ability for DOH to run standalone tests via regular Function objects as well as via test fixtures. Test fixtures are little more than a way of surrounding a test with initialization and clean up.
Rhino Test Harness Without Dojo
Without further ado, here's that test harness. Note that the
harness doesn't involve any Dojo specifics; it merely uses the
doh object. In particular, the
doh.register function is used in this example, where the first parameter specifies a module name (a JavaScript file located as a sibling ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access