Ticket #4651 (closed enhancement: fixed)
[patch] [cla] Adding the module dojox.testing.DocTest
| Reported by: | wolfram | Owned by: | alex |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.2 |
| Component: | Dojox | Version: | 0.9 |
| Severity: | normal | Keywords: | |
| Cc: |
Description (last modified by wolfram) (diff)
This class executes doctests. DocTests? are tests that are normally defined inside the comment, a doctest looks as if it was copied from the shell (which it mostly is). The lines of the test to execute start with ">>>" and the first line following that doesnt start like it is the exptected result. I.e. the following is a simple doctest, that will actually also be run if you run this class against this file here:
>>> 1+1 2 >>> "a"+"b" "ab"
To run the doctests of the DocTest? class itself, go in the FireBug? console and type:
>>> dojo.require("dojox.testing.DocTest");
>>> var doctest = new dojox.testing.DocTest();
>>> doctest.run("dojox.testing.DocTest");
it will then print out on the firebug console:
Test 1: OK: 1+1 // A simple test case. Terminated by an empty ...
Test 2: OK: 1==2
Test 3: OK: "a"+"b" // Also without the empty line before, thi...
Test 4: OK: var anything = "anything" // Multiple commands for...
Test 5: OK: true==true // Test a new line terminating the test...
Test 6: OK: true==true // Test a new test terminating the test...
Test 7: OK: true==true // Test a "not a comment"-line, especia...
Test 8: OK: [1,2,3,4]
Test 9: OK: true==true // Test code on new line terminating th...
Test 10: OK: false
Test 11: OK: "false"
Test 12: OK: true
Test 13: OK: 1
Test 14: OK: "s"
Test 15: OK: dojo.toJson({one:1})
for integrating it into your unittests you can simply check the property error, see the firebug output for what how it works:
>>> doctest.errors.length==0 true
Find some more in depth discussion in this article.