<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Writing Effective JavaScript Unit Tests with YUI Test</title>
	<atom:link href="http://www.yuiblog.com/blog/index.php/2009/01/05/effective-tests/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yuiblog.com/blog/2009/01/05/effective-tests/</link>
	<description>The official blog of the YUI Project.</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:46:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: Nicholas C. Zakas</title>
		<link>http://www.yuiblog.com/blog/2009/01/05/effective-tests/comment-page-1/#comment-596253</link>
		<dc:creator>Nicholas C. Zakas</dc:creator>
		<pubDate>Wed, 08 Dec 2010 18:54:02 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2009/01/05/effective-tests/#comment-596253</guid>
		<description>Hi Kaanta,

All of the examples I can share are currently in the documentation or included as part of the YUI download (check the tests directory in the ZIP file).

If you&#039;re testing a lot of interaction on a page, then I usually suggest loading YUI Test onto the actual page and running the tests there. That way, you don&#039;t have to worry about stubbing out certain pieces of the page to things working.</description>
		<content:encoded><![CDATA[<p>Hi Kaanta,</p>
<p>All of the examples I can share are currently in the documentation or included as part of the YUI download (check the tests directory in the ZIP file).</p>
<p>If you&#8217;re testing a lot of interaction on a page, then I usually suggest loading YUI Test onto the actual page and running the tests there. That way, you don&#8217;t have to worry about stubbing out certain pieces of the page to things working.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kaanta</title>
		<link>http://www.yuiblog.com/blog/2009/01/05/effective-tests/comment-page-1/#comment-596246</link>
		<dc:creator>kaanta</dc:creator>
		<pubDate>Wed, 08 Dec 2010 13:33:21 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2009/01/05/effective-tests/#comment-596246</guid>
		<description>Hi Nicholas,
I recently started exploring yuitest for unit testing of JS code on an existing portal that we have inherited for support and is already using some yui library 2. thanks for all the videos and blogs that you have put out.
1. are there examples/samples of yuitest being used in more practical/realistic scenarios like different contexts, extensive dom usgae etc. examples on yuitest site are very simplistic.
2. reason i ask is because content on pages is generally dynamic and is based on some pre-conditions..the container element is same but content changes. is it advisable to stub out different htmls for each scenario?
3. there could be some scripts that use lot of DOM. should entire html like original html be stubbed out in such cases.</description>
		<content:encoded><![CDATA[<p>Hi Nicholas,<br />
I recently started exploring yuitest for unit testing of JS code on an existing portal that we have inherited for support and is already using some yui library 2. thanks for all the videos and blogs that you have put out.<br />
1. are there examples/samples of yuitest being used in more practical/realistic scenarios like different contexts, extensive dom usgae etc. examples on yuitest site are very simplistic.<br />
2. reason i ask is because content on pages is generally dynamic and is based on some pre-conditions..the container element is same but content changes. is it advisable to stub out different htmls for each scenario?<br />
3. there could be some scripts that use lot of DOM. should entire html like original html be stubbed out in such cases.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicholas C. Zakas</title>
		<link>http://www.yuiblog.com/blog/2009/01/05/effective-tests/comment-page-1/#comment-540430</link>
		<dc:creator>Nicholas C. Zakas</dc:creator>
		<pubDate>Mon, 12 Jan 2009 21:00:29 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2009/01/05/effective-tests/#comment-540430</guid>
		<description>Hi Naresh,

Thanks for your insightful comments. Indeed, there are many schools of thoughts surrounding test methodology, and you&#039;ve touched on a few of them. I&#039;d just like to clarify a couple of the points.

Making the assertion failure message a statement of what should be happening isn&#039;t redundant, it&#039;s explanatory of what just happened. The test name and the failure message may be similar, and in this case are because the test is so simple; however, they may be very different if there are a number of assertions contained within the test.

My recommendation for setting up test suites and test cases is to get people started. I&#039;m not saying that every method should have one test, I&#039;m saying that every method should have a test case containing tests that explore each input-output set that you have. The point is to have a logical structure that maps directly to the objects that you are programming.

I hope this clarifies some of the points; thanks for your comments.</description>
		<content:encoded><![CDATA[<p>Hi Naresh,</p>
<p>Thanks for your insightful comments. Indeed, there are many schools of thoughts surrounding test methodology, and you&#8217;ve touched on a few of them. I&#8217;d just like to clarify a couple of the points.</p>
<p>Making the assertion failure message a statement of what should be happening isn&#8217;t redundant, it&#8217;s explanatory of what just happened. The test name and the failure message may be similar, and in this case are because the test is so simple; however, they may be very different if there are a number of assertions contained within the test.</p>
<p>My recommendation for setting up test suites and test cases is to get people started. I&#8217;m not saying that every method should have one test, I&#8217;m saying that every method should have a test case containing tests that explore each input-output set that you have. The point is to have a logical structure that maps directly to the objects that you are programming.</p>
<p>I hope this clarifies some of the points; thanks for your comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naresh Jain</title>
		<link>http://www.yuiblog.com/blog/2009/01/05/effective-tests/comment-page-1/#comment-540094</link>
		<dc:creator>Naresh Jain</dc:creator>
		<pubDate>Sun, 11 Jan 2009 18:09:28 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2009/01/05/effective-tests/#comment-540094</guid>
		<description>First of all, thanks for writing this wonderful blog entry. I would like to comment on the following:

&lt;blockquote&gt;In an object-oriented language like JavaScript, each method is considered to be a unit&lt;/blockquote&gt;
Personally prefer thinking of a class as a unit. The class provides me some behavior and I want to explain that behavior through my tests. Going at a method level seems that we are drilling into the implementation in some sense.

&lt;blockquote&gt;unit tests should test inputs and outputs&lt;/blockquote&gt;
I would prefer if the you qualifies your style of unit testing as state based unit testing. There is a different school of unit testing which believes in interaction based testing. Where its not so much about the output in terms of return values, changes in the state of variables, or thrown errors. The focus is on the interaction (method calls) with it&#039;s collaborators. 

&lt;blockquote&gt;In YUI Test, failure message is always the last argument of any assertion method&lt;/blockquote&gt;
They seem to have broken the xUnit convention. in xUnit failure message is always the first argument. 

You claims:

&lt;blockquote&gt;
&lt;code&gt;//Bad failure message
YAHOO.util.Assert.areEqual(&quot;Hello world&quot;, result, &quot;The result wasn&#039;t &#039;Hello world&#039;&quot;);

//Good failure message
YAHOO.util.Assert.areEqual(&quot;Hello world&quot;, result, &quot;Leading white space should be stripped.&quot;);&lt;/code&gt;&lt;/blockquote&gt;

While I agree with you that the second example is better than the first one, but I think the failure message in the second case is redundant. If you look at the whole test method below, 

&lt;code&gt;testTrimWithLeadingWhiteSpace: function(){
 var result = trim(&quot; Hello world&quot;);
 YAHOO.util.Assert.areEqual(&quot;Hello world&quot;, result, &quot;Leading white space should be stripped.&quot;);
}&lt;/code&gt;

The method name already tells you that leading white space should be trimmed or stripped out. In this specific case I would not give any failure message. If its your company&#039;s best practice to give one, then I would rather prefer your failure message as &quot;Leading white space was not stripped&quot;

&lt;blockquote&gt;Functional tests, on the other hand, cannot exist ahead of time because they are so tied to the user interface and how it changes in response to user interaction.&lt;/blockquote&gt;
This is not always true. In a lot of cases you can actually write your functional or acceptance tests before you create any code. Refer to Acceptance Test Driven Development

&lt;blockquote&gt;Create one test suite for every object you’re going to test&lt;/blockquote&gt;
Why is this important? I don&#039;t see how this will help?

&lt;blockquote&gt;Create one test case for every method of an object you’re going to test and add it to the object’s test suite.&lt;/blockquote&gt;
I would rather create a test class per important entity in my production code and write one test method per behavior the class fulfills. Sometimes I might have more than 1 test for one method and sometimes none. I&#039;m not sure if I would create a guideline saying every method should have one test.</description>
		<content:encoded><![CDATA[<p>First of all, thanks for writing this wonderful blog entry. I would like to comment on the following:</p>
<blockquote><p>In an object-oriented language like JavaScript, each method is considered to be a unit</p></blockquote>
<p>Personally prefer thinking of a class as a unit. The class provides me some behavior and I want to explain that behavior through my tests. Going at a method level seems that we are drilling into the implementation in some sense.</p>
<blockquote><p>unit tests should test inputs and outputs</p></blockquote>
<p>I would prefer if the you qualifies your style of unit testing as state based unit testing. There is a different school of unit testing which believes in interaction based testing. Where its not so much about the output in terms of return values, changes in the state of variables, or thrown errors. The focus is on the interaction (method calls) with it&#8217;s collaborators. </p>
<blockquote><p>In YUI Test, failure message is always the last argument of any assertion method</p></blockquote>
<p>They seem to have broken the xUnit convention. in xUnit failure message is always the first argument. </p>
<p>You claims:</p>
<blockquote><p>
<code>//Bad failure message<br />
YAHOO.util.Assert.areEqual("Hello world", result, "The result wasn't 'Hello world'");</p>
<p>//Good failure message<br />
YAHOO.util.Assert.areEqual("Hello world", result, "Leading white space should be stripped.");</code></p></blockquote>
<p>While I agree with you that the second example is better than the first one, but I think the failure message in the second case is redundant. If you look at the whole test method below, </p>
<p><code>testTrimWithLeadingWhiteSpace: function(){<br />
 var result = trim(" Hello world");<br />
 YAHOO.util.Assert.areEqual("Hello world", result, "Leading white space should be stripped.");<br />
}</code></p>
<p>The method name already tells you that leading white space should be trimmed or stripped out. In this specific case I would not give any failure message. If its your company&#8217;s best practice to give one, then I would rather prefer your failure message as &#8220;Leading white space was not stripped&#8221;</p>
<blockquote><p>Functional tests, on the other hand, cannot exist ahead of time because they are so tied to the user interface and how it changes in response to user interaction.</p></blockquote>
<p>This is not always true. In a lot of cases you can actually write your functional or acceptance tests before you create any code. Refer to Acceptance Test Driven Development</p>
<blockquote><p>Create one test suite for every object you’re going to test</p></blockquote>
<p>Why is this important? I don&#8217;t see how this will help?</p>
<blockquote><p>Create one test case for every method of an object you’re going to test and add it to the object’s test suite.</p></blockquote>
<p>I would rather create a test class per important entity in my production code and write one test method per behavior the class fulfills. Sometimes I might have more than 1 test for one method and sometimes none. I&#8217;m not sure if I would create a guideline saying every method should have one test.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nicholas C. Zakas</title>
		<link>http://www.yuiblog.com/blog/2009/01/05/effective-tests/comment-page-1/#comment-538871</link>
		<dc:creator>Nicholas C. Zakas</dc:creator>
		<pubDate>Wed, 07 Jan 2009 22:00:29 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2009/01/05/effective-tests/#comment-538871</guid>
		<description>The best solution I&#039;ve seen thusfar is to use Selenium to manage the browser lifecycle for testing. You can set it up to run periodically and then monitor the page for the results.</description>
		<content:encoded><![CDATA[<p>The best solution I&#8217;ve seen thusfar is to use Selenium to manage the browser lifecycle for testing. You can set it up to run periodically and then monitor the page for the results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://www.yuiblog.com/blog/2009/01/05/effective-tests/comment-page-1/#comment-538331</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Tue, 06 Jan 2009 04:19:46 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2009/01/05/effective-tests/#comment-538331</guid>
		<description>Are the YUI tests run automatically on a regular basis? If so can you share any information on how you do this? I&#039;m particularly interested in how you deal with spawning and closing the browser processes used to run the tests in during an automated build, and also how you collect and aggregate the test results for the build.</description>
		<content:encoded><![CDATA[<p>Are the YUI tests run automatically on a regular basis? If so can you share any information on how you do this? I&#8217;m particularly interested in how you deal with spawning and closing the browser processes used to run the tests in during an automated build, and also how you collect and aggregate the test results for the build.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

