📄 d_o_h_ unit testing the dojo toolkit.mht
字号:
<SPAN class=3Dsc2><A=20
href=3D"http://december.com/html/4/element/div.html"><SPAN=20
class=3Dkw2><div</SPAN></A> <SPAN class=3Dkw3>id</SPAN>=3D<SPAN=20
class=3Dst0>"t"</SPAN><SPAN class=3Dkw2>></SPAN></SPAN><BR> =
=20
<SPAN=20
class=3Dsc2><A =
href=3D"http://december.com/html/4/element/span.html"><SPAN=20
class=3Dkw2><span</SPAN></A> <SPAN class=3Dkw3>id</SPAN>=3D<SPAN=20
class=3Dst0>"c1"</SPAN><SPAN class=3Dkw2>></SPAN></SPAN>c1<SPAN =
class=3Dsc2><SPAN=20
class=3Dkw2></span></SPAN></SPAN><BR> =
=20
<SPAN class=3Dsc2><SPAN=20
class=3Dkw2></div></SPAN></SPAN><BR> =
<SPAN=20
class=3Dsc2><SPAN class=3Dkw2></body></SPAN></SPAN><BR><SPAN =
class=3Dsc2><SPAN=20
class=3Dkw2></html></SPAN></SPAN></DIV>
<P>The above code has several important features (in bold). First, we =
ensure=20
that the test system itself is loaded into the tested page. Without =
this, the=20
tests won't run. D.O.H. is smart enough to know if it's being loaded =
into a=20
child frame or as a parent document. If you load this file into a normal =
browser=20
window, the tests will still run, but you won't get the pretty D.O.H. =
chrome or=20
audio feedback. Instead, the results of <EM>only the tests from this =
page</EM>=20
will be sent to whatever console facility is available. </P>
<P>The second important feature of our tested URL is that it manually =
calls=20
<CODE class=3D"geshifilter javascript">tests.<SPAN =
class=3Dme1>run</SPAN><SPAN=20
class=3Dbr0>(</SPAN><SPAN class=3Dbr0>)</SPAN></CODE>, in this case =
after the page=20
has been loaded and tests have been registered (a good time to do it). =
There are=20
Dojo-isms in the test page, but they don't affect the important bits of =
the=20
system. You can still load the test system with <CODE=20
class=3D"geshifilter javascript"><script></CODE> tags and =
hard-wired URLs=20
and this file would participate in the larger test group correctly. </P>
<P>Since testing on loaded pages may take a long time (relatively), a =
default=20
timeout of 10 seconds per URL is provided. If your tested page requires =
more (or=20
less) time, you can pass an explicit timeout parameter to the <CODE=20
class=3D"geshifilter javascript">tests.<SPAN =
class=3Dme1>registerUrl</SPAN></CODE>=20
method: </P>
<DIV class=3Dgeshifilter style=3D"FONT-FAMILY: monospace">doh.<SPAN=20
class=3Dme1>registerUrl</SPAN><SPAN class=3Dbr0>(</SPAN><BR> =
=20
<SPAN class=3Dst0>"tests._base.NodeList"</SPAN>, <BR> =
=20
dojo.<SPAN class=3Dme1>moduleUrl</SPAN><SPAN =
class=3Dbr0>(</SPAN><SPAN=20
class=3Dst0>"tests"</SPAN>, <SPAN =
class=3Dst0>"_base/NodeList.html"</SPAN><SPAN=20
class=3Dbr0>)</SPAN>,<BR> <SPAN=20
class=3Dnu0>5000</SPAN><SPAN class=3Dbr0>)</SPAN>; <SPAN class=3Dco1>// =
5000ms, or 5=20
seconds</SPAN></DIV>
<H3>Running the tests in Rhino</H3>
<P>Here are some instructions for running the tests in Rhino. Ideally =
they=20
should run in any Rhino version 1.6R4 or later, however it has only be =
verified=20
to work with the custom_rhino.jar in Dojo's util repository (it is in=20
util/buildscripts/lib). Steps: </P>
<DIV class=3Dgeshifilter style=3D"FONT-FAMILY: monospace">> svn svn =
co http:<SPAN=20
class=3Dco1>//svn.dojotoolkit.org/dojo/view/anon/all/trunk =
dojo_0.9</SPAN><BR>>=20
cd dojo_0<SPAN class=3Dnu0>.9</SPAN><BR>> cd util/doh<BR>> java =
-jar ..<SPAN=20
class=3Dre0>/buildscripts/lib/</SPAN>custom_rhino.<SPAN =
class=3Dme1>jar</SPAN>=20
runner.<SPAN class=3Dme1>js</SPAN></DIV>
<H3>Including Tests From Custom Modules</H3>FIXME: TODOC=20
<H3>Including Tests Without Dojo</H3>FIXME: TODOC=20
<DIV class=3Dbook-navigation>
<DIV class=3D"page-links clear-block"><A class=3Dpage-previous=20
title=3D"Go to previous page"=20
href=3D"http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo/debugg=
ing-facilities/profiling">=E2=80=B9=20
Profiling</A><A class=3Dpage-up title=3D"Go to parent page"=20
href=3D"http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo-0">up<=
/A><A=20
class=3Dpage-next title=3D"Go to next page"=20
href=3D"http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo/perfor=
mance-optimization">Performance=20
Optimization =E2=80=BA</A></DIV></DIV></DIV>
<DIV class=3Dlinks>
<UL class=3D"links inline">
<LI class=3D"first book_printer"><A class=3Dbook_printer=20
title=3D"Show a printer-friendly version of this book page and its =
sub-pages."=20
href=3D"http://dojotoolkit.org/book/export/html/2653">Printer-friendly =
version</A>=20
<LI class=3Dcomment_forbidden><SPAN class=3Dcomment_forbidden><A=20
=
href=3D"http://dojotoolkit.org/user/login?destination=3Dnode/2653%2523com=
ment-form">Login</A>=20
or <A=20
=
href=3D"http://dojotoolkit.org/user/register?destination=3Dnode/2653%2523=
comment-form">register</A>=20
to post comments</SPAN>=20
<LI class=3D"last subscriptions_del_node"><A =
class=3Dsubscriptions_del_node=20
title=3D"Stop receiving an e-mail whenever a new comment is posted to =
this Book page."=20
=
href=3D"http://dojotoolkit.org/subscriptions/del/node/2653">Unsubscribe =
post</A>=20
</LI></UL></DIV></DIV>
<DIV id=3Dcomments><A id=3Dcomment-9017></A>
<DIV class=3Dcomment>
<H3 class=3Dtitle><A class=3Dactive=20
href=3D"http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo/d-o-h-=
unit-testing#comment-9017">test=20
fixture in URL-based Testing context</A></H3>
<DIV class=3Dsubmitted>Submitted by harobed on Sun, 11/18/2007 - =
12:20.</DIV>
<DIV class=3Dcontent>
<P>After some test, I think than syntax below don't work in URL-based =
Testing=20
context.</P><PRE> // a test fixture
{
name: "thingerTest",
setUp: function(){
this.thingerToTest =3D new Thinger();
this.thingerToTest.doStuffToInit();
},
runTest: function(){
doh.assertEqual("blah", =
this.thingerToTest.blahProp);
=
doh.assertFalse(this.thingerToTest.falseProp);
// ...
},
tearDown: function(){
}
},
// ...
</PRE></DIV>
<DIV class=3Dlinks>
<UL class=3Dlinks>
<LI class=3D"first last comment_forbidden"><SPAN =
class=3Dcomment_forbidden><A=20
=
href=3D"http://dojotoolkit.org/user/login?destination=3Dnode/2653%2523com=
ment-form">Login</A>=20
or <A=20
=
href=3D"http://dojotoolkit.org/user/register?destination=3Dnode/2653%2523=
comment-form">register</A>=20
to post comments</SPAN> </LI></UL></DIV></DIV><A =
id=3Dcomment-9071></A>
<DIV class=3Dcomment>
<H3 class=3Dtitle><A class=3Dactive=20
href=3D"http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo/d-o-h-=
unit-testing#comment-9071">Assert=20
Functions</A></H3>
<DIV class=3Dsubmitted>Submitted by mangr3n on Mon, 11/19/2007 - =
18:54.</DIV>
<DIV class=3Dcontent>
<P>It would be nice if the assertTrue, assertFalse, and assertEquals =
functions=20
would accept a string message argument. I'm reading through the code, =
and it=20
doesn't appear that they do.</P>
<P>David S. Boyer<BR>mangr3n at gmail (figure the rest out on your own=20
)</P></DIV>
<DIV class=3Dlinks>
<UL class=3Dlinks>
<LI class=3D"first last comment_forbidden"><SPAN =
class=3Dcomment_forbidden><A=20
=
href=3D"http://dojotoolkit.org/user/login?destination=3Dnode/2653%2523com=
ment-form">Login</A>=20
or <A=20
=
href=3D"http://dojotoolkit.org/user/register?destination=3Dnode/2653%2523=
comment-form">register</A>=20
to post comments</SPAN> </LI></UL></DIV></DIV><A =
id=3Dcomment-9209></A>
<DIV class=3Dcomment>
<H3 class=3Dtitle><A class=3Dactive=20
href=3D"http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo/d-o-h-=
unit-testing#comment-9209">The=20
"Running the tests in Rhino" section is slightly incorrect</A></H3>
<DIV class=3Dsubmitted>Submitted by Fracture on Thu, 11/22/2007 - =
03:56.</DIV>
<DIV class=3Dcontent>
<P>The "Running the tests in Rhino" section should contain :</P>
<P>java -jar ../shrinksafe/custom_rhino.jar runner.js</P>
<P>One other thing to mention, is the arguments that runner.js parses =
:</P>
<P>dojoUrl=3D/path/to/dojo.js</P>
<P>* load this dojo.js file instead of the default one</P>
<P>testUrl=3D/path/to/test.js</P>
<P>* load this javascript file after dojo.js</P>
<P>testModule=3Dtest.module1,test.module2</P>
<P>* dojo.require each test module in this comma delimited list</P>
<P>for example</P>
<P>java -jar ../shrinksafe/custom_rhino.jar runner.js=20
testModule=3Ddojo.tests.date</P></DIV>
<DIV class=3Dlinks>
<UL class=3Dlinks>
<LI class=3D"first last comment_forbidden"><SPAN =
class=3Dcomment_forbidden><A=20
=
href=3D"http://dojotoolkit.org/user/login?destination=3Dnode/2653%2523com=
ment-form">Login</A>=20
or <A=20
=
href=3D"http://dojotoolkit.org/user/register?destination=3Dnode/2653%2523=
comment-form">register</A>=20
to post comments</SPAN> </LI></UL></DIV></DIV><A =
id=3Dcomment-9210></A>
<DIV class=3Dcomment>
<H3 class=3Dtitle><A class=3Dactive=20
href=3D"http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo/d-o-h-=
unit-testing#comment-9210">Its=20
also worth pointing out</A></H3>
<DIV class=3Dsubmitted>Submitted by Fracture on Thu, 11/22/2007 - =
04:09.</DIV>
<DIV class=3Dcontent>
<P>Its also worth pointing out that runner.js should =
dojo.provide('doh.runner')=20
after it loads dojo.js. </P>
<P>runner.js does do dojo.provide('doh.runner') at the start, but when =
running=20
from the command line, dojo isn't yet loaded.</P>
<P>Without this, in my custom test, calls to dojo.require('doj.runner')=20
fail</P></DIV>
<DIV class=3Dlinks>
<UL class=3Dlinks>
<LI class=3D"first last comment_forbidden"><SPAN =
class=3Dcomment_forbidden><A=20
=
href=3D"http://dojotoolkit.org/user/login?destination=3Dnode/2653%2523com=
ment-form">Login</A>=20
or <A=20
=
href=3D"http://dojotoolkit.org/user/register?destination=3Dnode/2653%2523=
comment-form">register</A>=20
to post comments</SPAN> </LI></UL></DIV></DIV></DIV><!-- /main_content =
region --></DIV></DIV>
<DIV class=3D"col-c content-region-container">
<DIV id=3Dsidebar-right-container></DIV></DIV><BR class=3Dclear></DIV>
<DIV class=3Dcols-a50b50 id=3Dafter-content-block>
<DIV class=3D"col-a content-region-container" =
id=3Dafter-content-block-1></DIV>
<DIV class=3D"col-b content-region-container" =
id=3Dafter-content-block-2><BR=20
class=3Dclear></DIV><BR class=3Dclear></DIV><BR clear=3Dall></DIV>
<DIV class=3Dcontent-region-container>
<DIV id=3Dnavigation-block>
<DIV id=3Dbreadcrumb-block>
<DIV id=3Dbreadcrumbs>
<DIV class=3Dbreadcrumb><A href=3D"http://dojotoolkit.org/">Home</A> =
=C2=BB <A=20
href=3D"http://dojotoolkit.org/book/dojo-book-0-9-0">The Book of =
Dojo</A> =C2=BB <A=20
href=3D"http://dojotoolkit.org/book/dojo-book-0-9/part-4-meta-dojo-0">Par=
t 4:=20
Testing, Tuning and Debugging</A> =C2=BB D.O.H. Unit =
Testing</DIV></DIV></DIV>
<DIV class=3Dcols-abcd id=3Dmain-menu-block><!-- Block: menu -->
<DIV class=3D"block block-menu" id=3Dblock-menu-573>
<DIV class=3Dcontent>
<UL class=3Dmenu>
<LI class=3Dleaf id=3Dmenu-item-574><A title=3D"See the Dojo Toolkit =
in action!"=20
href=3D"http://dojotoolkit.org/demos">Demos</A>=20
<LI class=3Dexpanded id=3Dmenu-item-575><A=20
title=3D"Get started with the Dojo Toolkit, fast"=20
href=3D"http://dojotoolkit.org/docs/quickstart">Quick Start</A>=20
<UL class=3Dmenu>
<LI class=3Dleaf id=3Dmenu-item-576><A title=3D"Get the toolkit"=20
href=3D"http://dojotoolkit.org/downloads">Downloads</A>=20
<LI class=3Dleaf id=3Dmenu-item-577><A title=3D"See examples of the =
Dojo Toolkit"=20
href=3D"http://dojotoolkit.org/demos">Examples</A>=20
<LI class=3Dleaf id=3Dmenu-item-639><A=20
href=3D"http://dojotoolkit.org/spotlight">Spotlight</A> </LI></UL>
<LI class=3Dexpanded id=3Dmenu-item-578><A=20
href=3D"http://dojotoolkit.org/about">About</A>=20
<UL class=3Dmenu>
<LI class=3Dleaf id=3Dmenu-item-579><A=20
href=3D"http://dojotoolkit.org/about">Overview</A>=20
<LI class=3Dleaf id=3Dmenu-item-580><A=20
href=3D"http://dojotoolkit.org/about/features">Features</A>=20
<LI class=3Dleaf id=3Dmenu-item-581><A=20
href=3D"http://dojotoolkit.org/about/press">Press</A>=20
<LI class=3Dleaf id=3Dmenu-item-582><A=20
href=3D"http://dojotoolkit.org/about/contact">Contact</A>=20
</LI></UL></LI></UL></DIV></DIV><!-- Block: menu -->
<DIV class=3D"block block-menu" id=3Dblock-menu-589>
<DIV class=3Dcontent>
<UL class=3Dmenu>
<LI class=3Dexpanded id=3Dmenu-item-583><A=20
href=3D"http://dojotoolkit.org/downloads">Downloads</A>=20
<UL class=3Dmenu>
<LI class=3Dleaf id=3Dmenu-item-584><A=20
href=3D"http://dojotoolkit.org/downloads">Current releases</A>=20
<LI class=3Dleaf id=3Dmenu-item-585><A=20
href=3D"http://archive.dojotoolkit.org/nightly/">Nightly builds</A>=20
<LI class=3Dleaf id=3Dmenu-item-586><A=20
href=3D"http://archive.dojotoolkit.org/">Archives</A>=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -