W3C home > Mailing lists > Public > www-dom-ts@w3.org > October 2001

Test cases using list compares when they should be using multiple asserts

From: Curt Arnold <carnold@houston.rr.com>
Date: Fri, 26 Oct 2001 01:23:12 -0500
Message-ID: <005101c15de6$b056e2f0$7600a8c0@CurtMicron>
To: <www-dom-ts@w3.org>
Here is an excerpt from getElementsByTagNameNS02.xml

<var name="lname" type="DOMString"/>
<var name="result" type="List"/>
<var name="expectedResult" type="List">
<member>"emp"</member>
<member>"employee"</member>
</var>
<load var="doc" href="staffNS.xml" willBeModified="false"/>
<getElementsByTagNameNS interface="Document" obj="doc" var="newList" namespaceURI="namespaceURI" localName="localName"/>
<item interface="NodeList" obj="newList" var="newElement" index="3"/>
<prefix obj="newElement" var="prefix"/>
<append collection="result" obj="prefix"/>
<localName obj="newElement" var="lname"/>
<append collection="result" obj="lname"/>
<assertEquals actual="result" expected="expectedResult" id="throw_Equals" ignoreCase="false"/>
</test>

The fragment uses a list comparison to test the return value from Node.prefix and Node.localName.  A better way to write this is to have two distinct asserts.  Such as:

<var name="lname" type="DOMString"/>
<load var="doc" href="staffNS.xml" willBeModified="false"/>
<getElementsByTagNameNS interface="Document" obj="doc" var="newList" namespaceURI="namespaceURI" localName="localName"/>
<item interface="NodeList" obj="newList" var="newElement" index="3"/>
<prefix obj="newElement" var="prefix"/>
<assertEquals expected='"emp"' actual="prefix" ignoreCase="false" id="prefix"/>
<localName obj="newElement" var="lname"/>
<assertEquals expected='"employee"' actual="lname" ignoreCase="false" id="lname"/>
</test>


In addition to being shorter, the diagnostic messages are more meaningful.

Other cases that appear to use list comparisons inappropriately are:importNode01, importNode06, importNode07, importNode09, importNode11-14, removeAttributeNS02, setAttributeNS04, setAttributeNS09
Received on Friday, 26 October 2001 02:25:11 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 6 April 2009 12:58:45 GMT