Question

I'm looking at using the Dojo Objective Harness (DOH) for testing some custom JavaScript code. To that end I've read the following article:

http://www.ibm.com/developerworks/web/library/wa-aj-doh/index.html

and I have a question about the test case structure. The example shows that your test case modules in the same parent directory as dojo. This is a bit of a problem for us as we'd like to use DOH in multiple projects without having to include dojo in each and every one.

Does anyone know of a way to setup DOH to use the following structure:

  • dojotoolkit
    • dojo
    • dijit
    • dojox
    • util
  • project1
    • src
    • test
  • project2
    • src
    • test

Thanks...

Simon

Was it helpful?

Solution

First of all let me refer to my previous answer — it contains some useful links you want to read first.

DOH can be used separately from Dojo, all you need is the "util" project where DOH resides. It has zero Dojo dependencies. In order to set it up for your own code, just take a look how Dojo does it. Usually the main file is called runTests.html. It is pretty much a boiler-plate, I just copy it over, and modify the URL in it to point to my own test module. For example, the Dojo Core tests' runTests.html uses "dojo.tests.module" ⇒ dojo/tests/module.js. Usually my directory is the peer to Dojo, so it will be something like "my.tests.module" located in my/tests/module.js or whatever I decide to name it.

Look in the Dojo's module.js — it includes other JavaScript files using dojo.require() (you can include and register your files with DOH without Dojo). It is possible to include files from different levels, or you can include a file (like dojo.tests._base) that includes more files. This is the way to make modular unit tests.

It is possible to include HTML files as well. For example, dojo.tests._base.html does it.

In short: it is simple, just read the docs, and use existing Dojo tests as a cheatsheet.

OTHER TIPS

This article Unit Testing Custom Code with the Dojo Objective Harness http://www.sitepen.com/blog/2008/04/15/unit-testing-custom-code-with-the-dojo-objective-harness/ should give you what you need. It describes how to write unit tests for custom code in custom places.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top