<?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: Unit Testing C# Webpages</title>
	<atom:link href="http://www.nephandus.com/2010/05/06/unit-testing-c-webpages/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nephandus.com/2010/05/06/unit-testing-c-webpages/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 06 May 2010 16:48:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Chris</title>
		<link>http://www.nephandus.com/2010/05/06/unit-testing-c-webpages/comment-page-1/#comment-4</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Thu, 06 May 2010 16:48:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.nephandus.com/?p=21#comment-4</guid>
		<description>Throw away code is right.  I literally copied the first auto-generated stub that VisualStudio spat out and made a few quick change to it so it wouldn&#039;t be obviously broken.  All I really wanted to do was give the reader an indication of the production of a custom type that couldn&#039;t be reached.

The really long and descriptive names are a nice idea though; I&#039;ll be sure to integrate them.</description>
		<content:encoded><![CDATA[<p>Throw away code is right.  I literally copied the first auto-generated stub that VisualStudio spat out and made a few quick change to it so it wouldn&#8217;t be obviously broken.  All I really wanted to do was give the reader an indication of the production of a custom type that couldn&#8217;t be reached.</p>
<p>The really long and descriptive names are a nice idea though; I&#8217;ll be sure to integrate them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tweets that mention Nephandus » Blog Archive » Unit Testing C# Webpages -- Topsy.com</title>
		<link>http://www.nephandus.com/2010/05/06/unit-testing-c-webpages/comment-page-1/#comment-3</link>
		<dc:creator>Tweets that mention Nephandus » Blog Archive » Unit Testing C# Webpages -- Topsy.com</dc:creator>
		<pubDate>Thu, 06 May 2010 15:15:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.nephandus.com/?p=21#comment-3</guid>
		<description>[...] This post was mentioned on Twitter by Ryan Hagan, tgkillfile. tgkillfile said: I&#039;m having trouble setting up #unit-testing on a #CSharp webpage. Advice is welcome. http://bit.ly/9MlCZL #tdd #unittesting [...]</description>
		<content:encoded><![CDATA[<p>[...] This post was mentioned on Twitter by Ryan Hagan, tgkillfile. tgkillfile said: I&#39;m having trouble setting up #unit-testing on a #CSharp webpage. Advice is welcome. <a href="http://bit.ly/9MlCZL" rel="nofollow">http://bit.ly/9MlCZL</a> #tdd #unittesting [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://www.nephandus.com/2010/05/06/unit-testing-c-webpages/comment-page-1/#comment-2</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Thu, 06 May 2010 14:54:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.nephandus.com/?p=21#comment-2</guid>
		<description>Your suspicion is correct.  You&#039;re not using the recommended method for writing web page code.  First, I suspect that you&#039;re using a WebForms style of architecture, which is definitely *not* recommended now that .Net MVC is mature.  Since changing the architectural style of your application is a bit of an undertaking, I&#039;ll try to make my advice a little more relevant to your predicament.

The answer is to separate out the layers of your app in a better way, and start making use of Mocking.  You&#039;ll definitely need to do a little refactoring, but you can keep this manageable.  For a really great, and detailed, discussion on best practices when refactoring &quot;legacy&quot; code, pick up a copy of Working Effectively with Legacy Code by Michael Feathers.

Now, some advice.  I realize that the code you posted is example, throw-away code, but I want to look at that first, because it may shed some light on what you&#039;re trying to accomplish and maybe get you to start thinking about the problem from a different direction.  

The name of your test &quot;CreateTest&quot; is meaningless.  When you&#039;re looking at your test results and you see &quot;CreateTest failed&quot;, that doesn&#039;t tell you anything.  A better name for that test would be &quot;TestThatDefaultWidgetIsCreatedWhenEmptyWidgetNameIsPassedToFactory&quot;.

Unless your factory has a lot of conditional logic in it, there&#039;s not a lot of value in testing said factory.  You want to spend more of your time testing the different widget objects.  If I had a look at your test, I have a feeling I&#039;d see some higher level tests in there along side of that factory test.  You&#039;re probably testing at too high of a level.  There&#039;s nothing wrong with that, in fact, I highly encourage that, but be careful that you&#039;re not mixing unit and integration tests in the same fixture.

Now, addressing the comment that &quot;&#039;Widget&#039; and &#039;WidgetFactory&#039; are both custom types&quot; and that your project &quot;doesn’t know what a Widget is&quot; is a different matter.  You need to start making use of interfaces and polymorphism in your code.  Your code shouldn&#039;t ever depend on a specific implementation of a widget, it should depend on an interface.  What you have there is a classic case of high-level code knowing too much about implementation details.  Fixing this problem with the way the code is &quot;wired up&quot; will also address the problem you have with needing to compile anytime a small change is made a test needs to be rerun.  You&#039;ll only need a full compile when the interface changes, not the body of the methods.</description>
		<content:encoded><![CDATA[<p>Your suspicion is correct.  You&#8217;re not using the recommended method for writing web page code.  First, I suspect that you&#8217;re using a WebForms style of architecture, which is definitely *not* recommended now that .Net MVC is mature.  Since changing the architectural style of your application is a bit of an undertaking, I&#8217;ll try to make my advice a little more relevant to your predicament.</p>
<p>The answer is to separate out the layers of your app in a better way, and start making use of Mocking.  You&#8217;ll definitely need to do a little refactoring, but you can keep this manageable.  For a really great, and detailed, discussion on best practices when refactoring &#8220;legacy&#8221; code, pick up a copy of Working Effectively with Legacy Code by Michael Feathers.</p>
<p>Now, some advice.  I realize that the code you posted is example, throw-away code, but I want to look at that first, because it may shed some light on what you&#8217;re trying to accomplish and maybe get you to start thinking about the problem from a different direction.  </p>
<p>The name of your test &#8220;CreateTest&#8221; is meaningless.  When you&#8217;re looking at your test results and you see &#8220;CreateTest failed&#8221;, that doesn&#8217;t tell you anything.  A better name for that test would be &#8220;TestThatDefaultWidgetIsCreatedWhenEmptyWidgetNameIsPassedToFactory&#8221;.</p>
<p>Unless your factory has a lot of conditional logic in it, there&#8217;s not a lot of value in testing said factory.  You want to spend more of your time testing the different widget objects.  If I had a look at your test, I have a feeling I&#8217;d see some higher level tests in there along side of that factory test.  You&#8217;re probably testing at too high of a level.  There&#8217;s nothing wrong with that, in fact, I highly encourage that, but be careful that you&#8217;re not mixing unit and integration tests in the same fixture.</p>
<p>Now, addressing the comment that &#8220;&#8216;Widget&#8217; and &#8216;WidgetFactory&#8217; are both custom types&#8221; and that your project &#8220;doesn’t know what a Widget is&#8221; is a different matter.  You need to start making use of interfaces and polymorphism in your code.  Your code shouldn&#8217;t ever depend on a specific implementation of a widget, it should depend on an interface.  What you have there is a classic case of high-level code knowing too much about implementation details.  Fixing this problem with the way the code is &#8220;wired up&#8221; will also address the problem you have with needing to compile anytime a small change is made a test needs to be rerun.  You&#8217;ll only need a full compile when the interface changes, not the body of the methods.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

