Wednesday, April 16th, 2008

DOH, let me test my code!

Category: Dojo, Testing

<p>Dustin Machi has posted on DOH, the Dojo Objective Harness which is a testing framework for JavaScript.

It can be used with your own Dojo applications, and even without any Dojo at all.

To do this you need to follow a couple of patterns, and Dustin documents them so you can get going.

You end up putting the correct refresh code in your HTML:

  1. <meta http-equiv="REFRESH" content="0;
  2.    url=../../../util/doh/runner.html?testModule=company.tests.foo
  3.          &registerModulePath=company,../../company">

You register tests like this:

javascript
< view plain text >
  1. doh.register("project.tests.TestGroupA",
  2.        [
  3.                {
  4.                        name: "My Function Test [_myfunc()]",
  5.                        timeout: 4000,
  6.                        runTest: function(){
  7.                               var result = _myFunc("a", "b");
  8.                               doh.assertEqual("Foo", result);
  9.                             }
  10.                  }
  11.    ]
  12. );

Related Content:

2 Comments »

Comments feed TrackBack URI

What exactly are you testing?

Comment by Mikael Bergkvist — April 16, 2008

@Mikael: It is for unit testing javascript code. Dojo uses it for unit testing the its core, but really you can use it to test pretty much any js code that you want. You simply need to write a tests that does something and then use doh.assert* to verify the results are what are expected.

Comment by dmachi — April 16, 2008

Leave a comment

You must be logged in to post a comment.