<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" version="2.0"><channel><title>ISerializable - Roy Osherove's  Blog : Art Of Unit Testing</title><link>http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx</link><description>Tags: Art Of Unit Testing</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/ArtOfUnitTesting" type="application/rss+xml" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">ArtOfUnitTesting</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><title>Minimizing unit Test Fragility – 8 features in Typemock Isolator to help</title><link>http://weblogs.asp.net/rosherove/archive/2009/07/09/minimizing-unit-test-fragility-8-features-in-typemock-isolator-to-help.aspx</link><pubDate>Thu, 09 Jul 2009 22:52:50 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7144028</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=7144028</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/07/09/minimizing-unit-test-fragility-8-features-in-typemock-isolator-to-help.aspx#comments</comments><description>&lt;p&gt;in continuation &lt;a href="http://weblogs.asp.net/rosherove/archive/2009/07/09/preventing-fragile-tests-how-can-isolation-frameworks-help-or-hinder-your-goal.aspx"&gt;to my challenge&lt;/a&gt; (which no one had bothered answering, lazy web!)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/image_764311FD.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 15px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://weblogs.asp.net/blogs/rosherove/image_thumb_3B3B939A.png" width="240" height="205" /&gt;&lt;/a&gt; One of the things that inhibits unit tests in organizations is the idea of &lt;em&gt;fragile&lt;/em&gt; tests. a Fragile test is a test that can easily break when the production code changes. That’s not to say that tests should &lt;em&gt;never&lt;/em&gt; break as you change production code, but there are ways to minimize this effect so that when tests &lt;em&gt;do &lt;/em&gt;break, they break for the &lt;em&gt;right&lt;/em&gt;&amp;#160; reason.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;the right reason&lt;/strong&gt; is when a feature in production code isn’t working.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;the wrong reasons&lt;/strong&gt; can be many and varied. Of the most common ones is the idea of over specification in tests. The more your test expects of your code’s internal implementation, the more “specified” it is, the more “expectations” it has on the internals of the code. since internal code is more prone to change, so will the test break more often. so the situation can occur that the production code changed, but still gets the job done, but since it’s doing it differently internally, the test breaks even though the end result is still OK.&lt;/p&gt;  &lt;p&gt;One of the main ideas in the new Isolator API was to reduce the fragility of tests by default. there are several features in Typemock Isolator that remove lots of fragility from tests by default, compared to other tools:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;All Fakes are non strict by default&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Recursive Fakes&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Method stubs ignore parameters by default &lt;/li&gt;    &lt;li&gt;“From now on” Method behavior as a default &lt;/li&gt;    &lt;li&gt;Isolate.Swap.AllInstances &lt;/li&gt;    &lt;li&gt;Isolated.NonPublic APIs will not break when refactoring from private to public &lt;/li&gt;    &lt;li&gt;Ignore one or all static methods on a type &lt;/li&gt;    &lt;li&gt;True Properties &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;li&gt;&lt;u&gt;&lt;strong&gt;All Fakes are non strict by default&lt;/strong&gt;. &lt;/u&gt;    &lt;p&gt;when a fake object is strict, then it will throw an exception when someone calls one of its methods that wasn’t specifically “expected” by the test (or a different number of times than expected). since internal code can change and start interacting with other code in different ways, strict fakes will almost always fail your test on the lightest nuance of change. Most frameworks used to have strict fakes by default.&lt;/p&gt;    &lt;p&gt;Isolator has all fakes non strict by default. in fact, there is no “strict” mode at all.&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var fake = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;(); &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;//code under test can now call any method without the test needing to specify it. the test only needs to specify behavior of methods it cares about.&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;u&gt;&lt;strong&gt;Recursive Fakes&lt;/strong&gt;&lt;/u&gt;     &lt;p&gt;This is a feature first introduced by Isolator more than a couple of years ago and then adopted by Moq and Rhino Mocks. the idea is simple : allow chained calls in your code without the test needing to specify fakes at each hierarchy level. for example, calling MyFake.SomeProperty.DoSomething() will, by default, do nothing since its root is a fake object. the “SomeProperty” will be initialized by default to a fake object as well, recursively down the line.&lt;/p&gt;    &lt;p&gt;With other frameworks this will only work with interfaces, methods which are virtual and classes that are non sealed. Isolator can make this work with anything, including static methods and non sealed classes.&lt;/p&gt;    &lt;p&gt;var fake = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;(); &lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;//code under test can &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;fake.SomeProperty.DoSomething()&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;//or&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var propObj = fake.SomeProperty;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;propObj.DoSomething();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;As your internal code is refactored, or changed to call a method down the hierarchy, this should not break a test (as long as the method does not matter to the test)&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;Method stubs ignore parameters by default &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;all other frameworks except Isolator will use the values being sent to methods of fake objects during the “setup” phase, as expectations of these actual values. Isolator by default ignores values being sent in, and just returns the fake result we tell it to, no matter what was being sent in. Of course, you *could* tell it to use the exact argument values, but that is not the default behavior.&lt;/p&gt;    &lt;p&gt;other frameworks will require that you put in special constraints on each parameter value to say that you don’t care about the actual value.&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var o = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;const int IGNORED_VALUE=10;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;object IGNORED_OBJECT= null;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.WhenCalled(()=&amp;gt; o.SomeMethodWithParams(“ignored string”,IGNORED_VALUE,IGNORED_OBJECT) ).WillReturn(3);&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;this method will return 3 no matter what parameters are being sent to it. so internal code can change parameters slightly and it will still work.&lt;/p&gt;    &lt;p&gt;by specifying only on specify param values, we could be over specifying the test.&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;“From now on” Method behavior as a default &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;with Isolator, once you set behavior on a method (“Ignore”, WillReturn(..), WillThrowException(..) ), it will use that as its default behavior for all subsequent calls. That way, if the internal code ends up calling a method more than once, the test should not care about it (as long as the result does not hurt the test). This is great for ignore calls to “Log” objects and such, where you don’t know or care how many times it will be called. you just want to ignore them without having to worry if the code will use them or not.&lt;/p&gt;    &lt;p&gt;for example, the method from the code above will *always* return 3, no matter how many times it will be called.&lt;/p&gt;    &lt;p&gt;if we specified it twice with different return values, it will return the *last* behavior as the default, after it was called once with the previous behavior.&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;Isolate.Swap.AllInstances &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;This beauty will replace all existing and future instances of a specific type in the code under test with the fake type. that way you don’t care how many times some object might be created, or how many instances of it are used. for “util” type objects, this makes things a breeze to setup for a test that could be very complicated or impossible in other frameworks.&lt;/p&gt;    &lt;p&gt;as the internal code changes with usage of these types, the test will still pass.&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var fake = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.WhenCalled( ()=&amp;gt; fake.Foo() ).IgnoreCall();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.Swap.AllInstances&amp;lt;SomeType&amp;gt;().With(fake);&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;//now production code can do this:&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var x = new SomeType();//&amp;lt;—this will behave like the fake object we created&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;Isolated.NonPublic APIs will not break when refactoring from private to public &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;Isolator allows setting method behavior on non public methods as well:&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var x = new SomeObject();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.NonPublic.WhenCalled(x,”SomeMethod”).WillReturn(3);&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;The beauty is that if you do refactor the method to make it public, the test won’t nudge you or throw an exception. It will just work with public methods as well. You can then refactor the test without being a slave to it.&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;Ignore one or all static methods on a type &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;&lt;font color="#800000"&gt;Isolate.Fake.StaticMethods&amp;lt;SomeType&amp;gt;()&lt;/font&gt; will ignore all void methods on that type, and return recursive fakes on all functions. That way, if you add more methods to that type, the test won’t care about it.&amp;#160; great for utility style classes with lots of static methods.&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;&lt;u&gt;True Properties &lt;/u&gt;&lt;/strong&gt;    &lt;p&gt;“True properties” is a feature that Isolator picked up from Rhino Mocks – you can set properties on a fake object as if they were real properties.&lt;/p&gt;    &lt;p&gt;The nice thing is that if internal code then sets these properties to values you don’t care about, the test will work just fine. it’s also very readable.&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;var fake = Isolate.Fake.Instance&amp;lt;SomeType&amp;gt;();&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000"&gt;fake.SomeProperty=3; //will behave like a real property and return 3;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;/p&gt; &lt;/li&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7144028" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category></item><item><title>Art of Unit Testing on Hanselminutes</title><link>http://weblogs.asp.net/rosherove/archive/2009/07/07/art-of-unit-testing-on-hanselminutes.aspx</link><pubDate>Tue, 07 Jul 2009 12:28:40 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7142874</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=7142874</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/07/07/art-of-unit-testing-on-hanselminutes.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/image_5D7B81D7.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 10px 0px 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="left" src="http://weblogs.asp.net/blogs/rosherove/image_thumb_27F98A51.png" width="193" height="244" /&gt;&lt;/a&gt; &lt;a href="http://www.hanselman.com/blog/"&gt;Scott Hanselman&lt;/a&gt; took me in for a 30 minute interview about Unit Testing Dos and Don’ts in his podcast, Hanselminutes. It was a pleasure, and I hope to be there once more about other topics. Maybe in TechEd Berlin..&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.hanselminutes.com/default.aspx?showID=187"&gt;Have a listen&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7142874" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category></item><item><title>NDC 2009 – Done!</title><link>http://weblogs.asp.net/rosherove/archive/2009/06/22/ndc-2009-done.aspx</link><pubDate>Mon, 22 Jun 2009 11:46:14 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7131932</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=7131932</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/06/22/ndc-2009-done.aspx#comments</comments><description>&lt;p&gt;NDC 2009 was a blast!&lt;/p&gt;  &lt;p&gt;Thanks for all the great conversations :)&lt;/p&gt;  &lt;p&gt;Here’s what it looked like when you look up at a full room in NDC&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/DSC03827_0DB4B286.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="DSC03827" border="0" alt="DSC03827" src="http://weblogs.asp.net/blogs/rosherove/DSC03827_thumb_7D78C4BF.jpg" width="543" height="708" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/DSC03826_3D12FB85.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="DSC03826" border="0" alt="DSC03826" src="http://weblogs.asp.net/blogs/rosherove/DSC03826_thumb_06E15D69.jpg" width="750" height="578" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7131932" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category></item><item><title>Questions every team and dev lead should ask themselves</title><link>http://weblogs.asp.net/rosherove/archive/2009/06/16/questions-every-team-and-dev-lead-should-ask-themselves.aspx</link><pubDate>Tue, 16 Jun 2009 05:43:34 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7126581</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>10</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=7126581</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/06/16/questions-every-team-and-dev-lead-should-ask-themselves.aspx#comments</comments><description>&lt;p&gt;here are the questions that teams and team leads should be asking themselves on a daily\weekly basis.&lt;/p&gt;  &lt;p&gt;There are more, but these are the basics, to me. It’s part of the summary for the talk “Beautiful teams I am giving at SEConf and NDC. we do a lot of this stuff &lt;a href="http://www.typemock.com"&gt;over at work&lt;/a&gt;, and it’s proving itself on a daily basis.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Whole team&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;What can we automate?&lt;/li&gt;    &lt;li&gt;where are we &amp;quot;Reinventing the wheel&amp;quot;?&lt;/li&gt;    &lt;li&gt;what are the tools that slow us down?&lt;/li&gt;    &lt;li&gt;what tools can we use better?&lt;/li&gt;    &lt;li&gt;are there bugs that I could have found earlier? how do I make sure I find them earlier?&lt;/li&gt;    &lt;li&gt;when do we find out we built the right thing?&lt;/li&gt;    &lt;li&gt;when do we find out our code\design sucks? how can we make that earlier?&lt;/li&gt;    &lt;li&gt;How do we show progress at the team level? at the management level?&lt;/li&gt;    &lt;li&gt;How many meetings does each dev have every week? how can we remove them?&lt;/li&gt;    &lt;li&gt;Are we building by feature or by layer?&lt;/li&gt;    &lt;li&gt;can we make all our team sit in the same place? &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Team Lead&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;daily: what bottlenecks exist in the team? what have I solved?&lt;/li&gt;    &lt;li&gt;will my devs be better in a month or two than they were before? if not, how do I make that happen?&lt;/li&gt;    &lt;li&gt;what prevents my devs from working? what am I doing about this? &lt;/li&gt; &lt;/ol&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7126581" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category></item><item><title>Art Of Unit Testing available at Amazon</title><link>http://weblogs.asp.net/rosherove/archive/2009/06/06/art-of-unit-testing-available-at-amazon.aspx</link><pubDate>Sun, 07 Jun 2009 00:43:57 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7110468</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>9</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=7110468</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/06/06/art-of-unit-testing-available-at-amazon.aspx#comments</comments><description>&lt;p&gt;My book, &lt;a href="http://www.amazon.com/exec/obidos/ASIN/1933988274/iserializable-20"&gt;The Art Of Unit Testing&lt;/a&gt;, is now &lt;strong&gt;in stock&lt;/strong&gt; at Amazon. If you’ve read the book, I’d love it if you &lt;a href="http://www.amazon.com/exec/obidos/ASIN/1933988274/iserializable-20"&gt;put in a review on that page.&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7110468" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category></item><item><title>Using Explicit Arrange,Act,Assert scopes in tests – thoughts?</title><link>http://weblogs.asp.net/rosherove/archive/2009/06/02/using-explicit-arrange-act-assert-scopes-in-tests-thoughts.aspx</link><pubDate>Wed, 03 Jun 2009 00:55:11 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7106613</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>17</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=7106613</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/06/02/using-explicit-arrange-act-assert-scopes-in-tests-thoughts.aspx#comments</comments><description>&lt;p&gt;What are your thoughts on this style of writing? &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Specifically the “Explicit” way of defining arrange, act and assert scopes.&lt;/li&gt;    &lt;li&gt;also, given the name of the test, where should the call to “OnApplyTemplate” be (if you’ve never seen the code)?&lt;/li&gt;    &lt;li&gt;which version makes more sense to you? A, or B?&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;version A:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/image_1782D79C.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rosherove/image_thumb_6AC9F7F5.png" width="575" height="416" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;version B:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/image_2C348482.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rosherove/image_thumb_062EAE5F.png" width="564" height="412" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7106613" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/.Net+2.0/default.aspx">.Net 2.0</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Testing that an event was raised</title><link>http://weblogs.asp.net/rosherove/archive/2009/05/23/testing-that-an-event-was-raised.aspx</link><pubDate>Sat, 23 May 2009 18:25:20 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7095427</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=7095427</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/05/23/testing-that-an-event-was-raised.aspx#comments</comments><description>&lt;p&gt;This question keeps coming up: “How can I test that an event was actually raised from my class under test?”&lt;/p&gt;  &lt;p&gt;actually, there is an easy way to check if an event was raised.    &lt;br /&gt;you subscribe to the event in your test, and in the event handler you set a boolean flag to true. then you just assert on the flag.     &lt;br /&gt;here is a quick example: &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000"&gt;public void Test()      &lt;br /&gt;{       &lt;br /&gt;bool wasRaised=false;       &lt;br /&gt;var button = new Button;       &lt;br /&gt;button.Click += ()=&amp;gt; wasRaised=true;       &lt;br /&gt;button.DoSomethingThatShouldHaveTriggeredTheEvent();       &lt;br /&gt;Assert.IsTrue(wasRaised);       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;If you feel less comfortable using lambdas:&lt;/b&gt; &lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="c"&gt;public void Test()      &lt;br /&gt;{       &lt;br /&gt;bool wasRaised=false;       &lt;br /&gt;var button = new Button;       &lt;br /&gt;button.Click += delegate&lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font color="#800000" face="c"&gt;{ &lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000" face="c"&gt;wasRaised=true&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;&lt;font color="#800000" face="c"&gt;};&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font color="#800000" face="c"&gt;button.DoSomethingThatShouldHaveTriggeredTheEvent();      &lt;br /&gt;Assert.IsTrue(wasRaised);       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Unfortunately, with VB.NET’s current version, doing this in a single method is next to impossible, so you are forced to register to the event with a method at the class level, and check that:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Code (VB.NET):&lt;/b&gt; &lt;/p&gt; &lt;font color="#800000" face="Consolas"&gt;dim wasRaised as Boolean=false;    &lt;br /&gt;&lt;/font&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;strong&gt;public sub test()        &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;wasRaised=false     &lt;br /&gt;dim button = new Button()      &lt;br /&gt;AddHandler( button.Click , AddressOf(OnClick))&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;button.DoSomethingThatShouldHaveTriggeredTheEvent()     &lt;br /&gt;Assert.IsTrue(wasRaised);      &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;strong&gt;end sub&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;strong&gt;public sub OnClick(source as object,e as EventArgs)&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;wasRaised=true&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#800000" face="Consolas"&gt;&lt;strong&gt;end sub&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7095427" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category></item><item><title>Art Of Unit Testing (The Samurai Book)– Get it now, it’s done.</title><link>http://weblogs.asp.net/rosherove/archive/2009/05/20/art-of-unit-testing-the-samurai-book-get-it-now-it-s-done.aspx</link><pubDate>Wed, 20 May 2009 21:22:14 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7093756</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>16</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=7093756</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/05/20/art-of-unit-testing-the-samurai-book-get-it-now-it-s-done.aspx#comments</comments><description>&lt;p&gt;The time has actually come. After 2.5 years, and two kids, &lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91" target="_blank"&gt;my book is finally done&lt;/a&gt; and is available in full form as an EBook. at the end of the month it will be in print form. Now would be the time to get it, when it is still at a “pre-order” pricing. Get the preorder price either &lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91" target="_blank"&gt;at Manning&lt;/a&gt;(along with the EBook) or at &lt;a href="http://www.amazon.com/exec/obidos/ASIN/1933988274/iserializable-20" target="_blank"&gt;the amazon page&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;I love the cover image. How about we call this “The Samurai book” from now on?&lt;/p&gt;  &lt;p&gt;This is the book that I wished I had when I started out writing my first tests, and that combines my knowledge about unit testing from the past 5-6 years or so working with companies on real projects (and real failures).&lt;/p&gt;  &lt;p&gt;It contains things I have not seen in other places – writing readable, maintainable and trustworthy tests, as well as guidelines on how to review someone else’s tests and what to watch out for.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91" target="_blank"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="image" border="0" alt="image" align="left" src="http://weblogs.asp.net/blogs/rosherove/image_6E3CE98B.png" width="273" height="347" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I was lucky to have the foreword written by no other than &lt;a href="http://www.amazon.com/exec/obidos/ASIN/0131177052/iserializable-20" target="_blank"&gt;Michael-Legacy-Code-Feathers&lt;/a&gt; himself, and with some great quotes including one from Kent Beck about the book.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here is the &lt;a href="http://www.manning.com/osherove/excerpt_contents.html" target="_blank"&gt;Table of Contents&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Free Chapters&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The book comes with two free chapters:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Chapter 1 &lt;/strong&gt;– &lt;a href="http://www.manning.com/osherove/SampleChapter1.pdf" target="_blank"&gt;The basics of unit testing(PDF)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Chapter 3 &lt;/strong&gt;– &lt;a href="http://www.manning.com/osherove/SampleChapter3.pdf" target="_blank"&gt;Using Stubs to Break Dependencies (PDF)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Or &lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91" target="_blank"&gt;get the full book&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Book description:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Unit testing, done right, can mean the difference between a failed project and a successful one, between a maintainable code base and a code base that no one dares touch, and between getting home at 2 AM or getting home in time for dinner, even before a release deadline.&lt;/p&gt;  &lt;p&gt;&lt;i&gt;The Art of Unit Testing&lt;/i&gt; builds on top of what's already been written about this important topic. It guides you step by step from simple tests to tests that are maintainable, readable, and trustworthy. It covers advanced subjects like mocks, stubs, and frameworks such as Typemock Isolator and Rhino Mocks. And you'll learn about advanced test patterns and organization, working with legacy code and even untestable code. The book discusses tools you need when testing databases and other technologies. It's written for .NET developers but others will also benefit from this book.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What’s inside:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Test Review Guidelines &lt;/li&gt;    &lt;li&gt;How to create readable, maintainable, trustworthy tests &lt;/li&gt;    &lt;li&gt;Stubs, mock objects, and automated frameworks &lt;/li&gt;    &lt;li&gt;Working with .NET tools, including NUnit, Rhino Mocks and Typemock Isolator &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7093756" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category></item><item><title>Test Review #3 – Unity</title><link>http://weblogs.asp.net/rosherove/archive/2009/03/23/test-review-3-unity.aspx</link><pubDate>Mon, 23 Mar 2009 05:58:55 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6994263</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>9</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=6994263</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/03/23/test-review-3-unity.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;Watch previous videos:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/rosherove/archive/2009/03/20/test-review-1-nerddinner.aspx"&gt;Test Review #1 – NerdDinner&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/rosherove/archive/2009/03/21/test-review-2-asp-net-mvc-unit-tests.aspx"&gt;Test Review #2 – ASP.NET MVC&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370" id="viddler_RoyOsherove_6"&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;param name="movie" value="http://www.viddler.com/player/43373a0e/" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;embed src="http://www.viddler.com/player/43373a0e/" wmode="transparent" width="437" height="370" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" name="viddler_RoyOsherove_6" /&gt;&lt;/embed&gt;&lt;/object&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In this video I go over the tests for Microsoft Unity Application Block.&lt;/p&gt;  &lt;p&gt;Overall the quality of the tests in Unity is pretty good! I could certainly recommend that people look at them as examples of a bunch of tests against a framework, which are mostly very readable and maintainable. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Things I walk through:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Using [Ignore] &lt;/li&gt;    &lt;li&gt;exploration testing &lt;/li&gt;    &lt;li&gt;magic numbers and strings &lt;/li&gt;    &lt;li&gt;un-needed asserts &lt;/li&gt;    &lt;li&gt;Stub hard coded behavior &lt;/li&gt;    &lt;li&gt;handling config files in tests &lt;/li&gt;    &lt;li&gt;Asserts hidden in a utility method &lt;/li&gt;    &lt;li&gt;more naming conventions &lt;/li&gt;    &lt;li&gt;Separating integration tests &lt;/li&gt;    &lt;li&gt;“smart” code that is less readable &lt;/li&gt;    &lt;li&gt;Meaningless “isNotNull” tests &lt;/li&gt;    &lt;li&gt;cleaner ways of expecting exceptions &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6994263" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Testing+Guidelines/default.aspx">Testing Guidelines</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/TestReview/default.aspx">TestReview</category></item><item><title>Test Review #2 – ASP.NET MVC Unit Tests</title><link>http://weblogs.asp.net/rosherove/archive/2009/03/21/test-review-2-asp-net-mvc-unit-tests.aspx</link><pubDate>Sun, 22 Mar 2009 03:42:38 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6988868</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>17</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=6988868</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/03/21/test-review-2-asp-net-mvc-unit-tests.aspx#comments</comments><description>&lt;p&gt;See other reviews: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/rosherove/archive/2009/03/20/test-review-1-nerddinner.aspx"&gt;Review #1: NerdDinner&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here’s the second video review of Unit Tests. This is another one written by Microsoft – &lt;a href="http://www.codeplex.com/aspnet"&gt;ASP.NET MVC&lt;/a&gt; (&lt;a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471"&gt;source&lt;/a&gt;). &lt;/p&gt;  &lt;p&gt;First, it’s important to state how surprised I was by the &lt;strong&gt;high quality&lt;/strong&gt; of the tests in MVC. The tests are &lt;strong&gt;readable, maintainable and trustworthy, &lt;/strong&gt;with very little issues that I could find. whatever Issues I found are rather easy to fix. In any case, if one is looking for examples of systems written in what seems almost entirely in TDD, or at the minimum with very good testing guidance, ASP.NET MVC should be a good stop to look at.&lt;/p&gt;  &lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/a30fe2d4/" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;embed src="http://www.viddler.com/player/a30fe2d4/" width="437" height="370" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" wmode="transparent" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;  &lt;p&gt;Issues discussed in this video:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Implementing RowTest with MSTest, and the importance of naming (14:00)&lt;/li&gt;    &lt;li&gt;Verify() that is splitted from the mock expectations (17:00)&lt;/li&gt;    &lt;li&gt;some naming conventions&lt;/li&gt;    &lt;li&gt;Over-specification in tests (mainly more than one mock object per test)&lt;/li&gt;    &lt;li&gt;verifying mocks when it’s not required&lt;/li&gt;    &lt;li&gt;logic inside tests (concatenation)&lt;/li&gt;    &lt;li&gt;test factory methods with too much logic&lt;/li&gt;    &lt;li&gt;a very good example of when &lt;strong&gt;multiple asserts&lt;/strong&gt; is really bad (11:50)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Again – I’m very pleased with the test quality. Now is the time to make sure the things above are fixed. they are still important!&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6988868" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/.Net+Original/default.aspx">.Net Original</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/.Net+2.0/default.aspx">.Net 2.0</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Testing+Guidelines/default.aspx">Testing Guidelines</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/TestReview/default.aspx">TestReview</category></item><item><title>Test Review #1 - NerdDinner</title><link>http://weblogs.asp.net/rosherove/archive/2009/03/20/test-review-1-nerddinner.aspx</link><pubDate>Fri, 20 Mar 2009 11:45:53 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6981302</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>41</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=6981302</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/03/20/test-review-1-nerddinner.aspx#comments</comments><description>&lt;p&gt;I’ve decided to start doing some test reviews of tests that I see in the wild. I figured it’s the best way to show people what I mean when I say they do not have readable, maintainable or trustworthy tests.&lt;/p&gt;  &lt;p&gt;The first episode is the review of the tests from the &lt;a href="http://nerddinner.codeplex.com/"&gt;NerdDinner MVC source code&lt;/a&gt;. It’s 30 minutes long. and it was shot at 2AM, so I’m quite cranky. But the tests sure don’t try to ease my mind, and only make me crankier. &lt;/p&gt;  &lt;p&gt;If you have tests you’d like me to review send an email to Roy AT osherove.com with the subject “Test Review [project name]”&lt;/p&gt;  &lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/6180e63a/" /&gt;&lt;param name="allowScriptAccess" value="always" /&gt;&lt;param name="allowFullScreen" value="true" /&gt;&lt;param name="wmode" value="transparent" /&gt;&lt;embed src="http://www.viddler.com/player/6180e63a/" width="437" height="370" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" wmode="transparent" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;problems that are dealt with in this video:&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Naming conventions&lt;/li&gt;    &lt;li&gt;Magic strings in tests&lt;/li&gt;    &lt;li&gt;Hard coded values in hand written stubs&lt;/li&gt;    &lt;li&gt;Magic assertions (expecting a value that no one understand why it should be that value)&lt;/li&gt;    &lt;li&gt;Lack of tests&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6981302" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/TestReview/default.aspx">TestReview</category></item><item><title>API design values and decision matrix</title><link>http://weblogs.asp.net/rosherove/archive/2009/03/17/api-design-values-and-decision-matrix.aspx</link><pubDate>Tue, 17 Mar 2009 14:56:56 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6970509</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=6970509</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/03/17/api-design-values-and-decision-matrix.aspx#comments</comments><description>&lt;p&gt;We’ve come to a nice way of deciding upon features in the Isolator API. This is what happens when your end product is an API for programmers.&lt;/p&gt;  &lt;p&gt;First, we realized that we &lt;a href="http://www.elilopian.com/2009/03/12/management-for-geeks-have-a-good-fight/"&gt;must argue about it&lt;/a&gt;. For each type of new feature in the isolator API, we put up on the white board several version of the API that we can’t seem to decide about, and then ask everyone on the team to say what they think. If everyone agrees, then we ask people to defend the opposite side and explain why an API is not good.&lt;/p&gt;  &lt;p&gt;We came to several agreed upon values for the C# API, that help us judge the usability of it:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Consistency – is the new API consistent with the other APIs that already exist, or does it go against the regular way things are done? &lt;/li&gt;    &lt;li&gt;Discoverability – If a user knew they wanted to do thing X, would they know to use the API without help? simply from intellisense? &lt;/li&gt;    &lt;li&gt;Explicitness – we decided early on to be as explicit as possible about the API, so that the least guessing needs to take place by the user &lt;/li&gt;    &lt;li&gt;Single point of entry – everything should start from a single point (Isolate.Something()) &lt;/li&gt;    &lt;li&gt;Readability for the reader, not the writer (if you didn’t write the test would you find it easy to understand what it does?) &lt;/li&gt;    &lt;li&gt;Single way to achieve things – is there more than one way to do a task with the new API? &lt;/li&gt;    &lt;li&gt;Backwards compatibility – do we break an existing feature and cause some heartache&amp;#160; for users? &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;We measure the various versions of an API by putting it in a matrix and setting “V” or “X” on each of them (if we can’t agree it’s a V with a line on it).&lt;/p&gt;  &lt;p&gt;then we have a better idea of what makes more sense.&lt;/p&gt;  &lt;p&gt;I admit we still haven’t come up with a single set of values for the VB API, but I’ll try to define it here:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Does not require use of Action&amp;lt;T&amp;gt;&lt;/li&gt;    &lt;li&gt;Consistent with the way a VBer would use other APIs&lt;/li&gt;    &lt;li&gt;Explicit&lt;/li&gt;    &lt;li&gt;Readable&lt;/li&gt;    &lt;li&gt;Single way to achieve things&lt;/li&gt;    &lt;li&gt;Backwards compatible&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;note that “single point of entry” is not included. That was a design decision we made early on.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6970509" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category></item><item><title>Art of unit Testing goes to print in April</title><link>http://weblogs.asp.net/rosherove/archive/2009/03/16/art-of-unit-testing-goes-to-print-in-april.aspx</link><pubDate>Mon, 16 Mar 2009 23:33:45 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6968598</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>9</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=6968598</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2009/03/16/art-of-unit-testing-goes-to-print-in-april.aspx#comments</comments><description>&lt;p&gt;The &lt;a href="http://www.ArtOfUnitTesting.com"&gt;book of never ending production&lt;/a&gt; is now actually near the end. &lt;/p&gt;  &lt;p&gt;the projected print date of “Art Of Unit Testing” is now April 30 and I’m happy to see the &lt;a href="http://www.amazon.com/exec/obidos/ASIN/1933988274/iserializable-20"&gt;Amazon page for the book&lt;/a&gt; already has one review of the &lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91"&gt;early access version&lt;/a&gt; (though he &lt;a href="http://www.amazon.com/Must-Have-Books-for-your-shelf/forum/Fx3HZHLJNJKXXLK/Tx23FXJ7W0JBTWI/1/ref=cm_cd_dp_tft_tp?_encoding=UTF8&amp;amp;asin=1933988274&amp;amp;store=books"&gt;totally destroys my spelling and book formatting abilities&lt;/a&gt;, he likes the content, so I’m happy)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.manning.com/affiliate/idevaffiliate.php?id=462_91"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/rosherove/image_5FC0326C.png" width="244" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6968598" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile+Related/default.aspx">Agile Related</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category></item><item><title>Unit Testing in silverlight land with Typemock Isolator</title><link>http://weblogs.asp.net/rosherove/archive/2008/12/27/unit-testing-in-silverlight-land-with-typemock-isolator.aspx</link><pubDate>Sat, 27 Dec 2008 21:54:07 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6808150</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>7</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=6808150</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2008/12/27/unit-testing-in-silverlight-land-with-typemock-isolator.aspx#comments</comments><description>&lt;p&gt;I’ve been asked quite a lot recently whether one can write unit tests and isolate logical code that runs inside a silverlight application. Up until today my initial answer was&amp;#160; ‘no’ because silverlight runs under different versions of mscorlib.dll.&lt;/p&gt;  &lt;p&gt;however.&lt;/p&gt;  &lt;p&gt;Today I actually gave it a try and realized that writing unit tests (not &lt;a href="http://www.jeff.wilcox.name/2008/03/silverlight2-unit-testing/"&gt;integration tests, as the silverlight test framework&lt;/a&gt; allows) against silverlight based code is possible and quite easy. Just like any other code that relies on a third party platform (like sharepoint code) the silverlight related code might have various dependencies.&lt;/p&gt;  &lt;p&gt;I’m going to show how to use &lt;a href="http://www.typemock.com"&gt;Typemock Isolator&lt;/a&gt; to overcome a couple of simple silverlight dependencies (using HtmlPage) and how to setup a test project against a silverlight project (with NUnit or MsTest)&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Assumptions:&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;You have an open solution&lt;/li&gt;    &lt;li&gt;the solution contains a silverlight class library or silverlight application project&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#800080"&gt;To setup a test project against silverlight using MSTest:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Add a new test project to the solution&lt;/li&gt;    &lt;li&gt;Remove all the existing classes (Database test, ordered test etc..) so that you are only left with the unit test class (UnitTest1). &lt;/li&gt;    &lt;li&gt;Remove all useless comments and crud code from the test class so that you are only left with a test method (no comments, not even the TestContext)&lt;/li&gt;    &lt;li&gt;Add a reference to the silverlight versions of “System.dll”, “System.Windows.dll” to the test project. (usually located under “C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\” (remove existing reference to system.dll if you need to first)&lt;/li&gt;    &lt;li&gt;Add a reference to the project under test&lt;/li&gt;    &lt;li&gt;You can now write tests against the object model (standard classes)&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#800080"&gt;To setup a test project against silverlight using NUnit or MbUnit:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Add a new class library to the solution as your test project&lt;/li&gt;    &lt;li&gt;Add a reference to the silverlight versions of “System.dll”, “System.Windows.dll” to the test project. (usually located under “C:\Program Files\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\” (remove existing reference to system.dll if you need to first)&lt;/li&gt;    &lt;li&gt;Add a reference to the project under test&lt;/li&gt;    &lt;li&gt;You can now write tests against the object model (standard classes)&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#800080"&gt;How to break the dependencies&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now, here is a simple example of code that has a silverlight dependency we’d like to test:&lt;/p&gt;  &lt;p&gt;Let’s say we have a class in the silverlight project called ChatSession (I’m basing this on ScottGu’s Chat demo). but it’s constructor looks like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/WindowClipping_1HG2PA.png"&gt;&lt;img title="WindowClipping" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="145" alt="WindowClipping" src="http://weblogs.asp.net/blogs/rosherove/WindowClipping_thumb_qfKb+Q.png" width="408" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;What if we wanted to control during our test whether the page is enabled or disabled? &lt;/p&gt;  &lt;p&gt;Here’s one way to do it using Isolator:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In your test project add two references under the .NET tab: “Typemock Isolator” and “Typemock ArrangeActAssert”&lt;/li&gt;    &lt;li&gt;Write the following test:&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/WindowClipping%20(2)_RPaiTA.png"&gt;&lt;img title="WindowClipping (2)" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="194" alt="WindowClipping (2)" src="http://weblogs.asp.net/blogs/rosherove/WindowClipping%20(2)_thumb_4mlE+A.png" width="451" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Using Isolate.WhenCalled() we are able to circumvent any method (static or not) to return whatever we want, or throw an exception.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here’s a more interesting case. Let’s say we have a method that modifies the current page and shows some html to the user in a span tag:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/WindowClipping%20(3)_mjd/2g.png"&gt;&lt;img title="WindowClipping (3)" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="112" alt="WindowClipping (3)" src="http://weblogs.asp.net/blogs/rosherove/WindowClipping%20(3)_thumb_Bf9WqQ.png" width="581" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;here is one way to write a test that makes sure that the right text is set into the message element in the page, without needing to have a real page present:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/WindowClipping%20(4)_7L0kSA.png"&gt;&lt;img title="WindowClipping (4)" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="377" alt="WindowClipping (4)" src="http://weblogs.asp.net/blogs/rosherove/WindowClipping%20(4)_thumb_elBN9g.png" width="626" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;There are several things to note here:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;HtmlElement is &lt;strong&gt;Sealed&lt;/strong&gt; has an &lt;strong&gt;internal constructor&lt;/strong&gt;, but we can still create a fake instance of it using Isolator. None of the other frameworks can do this.&lt;/li&gt;    &lt;li&gt;We are returning a fake object from a &lt;strong&gt;method call chain &lt;/strong&gt;(HtmlPage.Document.GetElementById ) without needing to create a separate stub for &lt;strong&gt;document&lt;/strong&gt;. None of the other frameworks can do this (especially since it is based on a &lt;strong&gt;static &lt;/strong&gt;method call to begin with)&lt;/li&gt;    &lt;li&gt;We assert in the end that the method was indeed called with the correct arguments without needing to change a single piece of code. Granted, I wouldn’t write code like this (I like decoupling!) but sometimes you just don’t have the ability to change existing code.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;If you are developing an open source silverlight project, it is important to note that there is a free full version of isolator for open source projects with full functionality.&lt;/p&gt;  &lt;p&gt;These are just the beginning of my journey into silverlight unit testing. I’m looking for good code examples that you might want to test, with various dependencies that need breaking. your comments are appreciated.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6808150" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Typemock/default.aspx">Typemock</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Silverlight/default.aspx">Silverlight</category></item><item><title>Isolator Feature Focus: Duck Typing and Isolate.Swap</title><link>http://weblogs.asp.net/rosherove/archive/2008/11/02/isolator-feature-focus-duck-typing-and-isolate-swap.aspx</link><pubDate>Sun, 02 Nov 2008 12:25:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6716046</guid><dc:creator>RoyOsherove</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://weblogs.asp.net/rosherove/rsscomments.aspx?PostID=6716046</wfw:commentRss><comments>http://weblogs.asp.net/rosherove/archive/2008/11/02/isolator-feature-focus-duck-typing-and-isolate-swap.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.typemock.com/commdl.php"&gt;Typemock Isolator 5.1.1&lt;/a&gt; has been released, and this release brings with it some awesome (seriously) features that are unique fro any other framework I've seen.&lt;/p&gt;  &lt;p&gt;a &lt;a href="http://blog.typemock.com/2008/10/typemock-isolator-511-is-out.html"&gt;good overview of features can be found here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The Isolator Swap feature &lt;/strong&gt;allows swapping calls between real and fake objects (kind like redirects) so that any relevant calls made against the real object will be redirected and invoked on the fake object. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Here's how you use it:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/WindowsLiveWriter/IsolatorFeatureFocusDuckTypingandIs.Swap_CC8A/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="133" alt="image" src="http://weblogs.asp.net/blogs/rosherove/WindowsLiveWriter/IsolatorFeatureFocusDuckTypingandIs.Swap_CC8A/image_thumb.png" width="340" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Unlike doing a standard &amp;quot;WhenCalled()&amp;quot; on some object method and telling what its custom behavior will be, &amp;quot;Swapping&amp;quot;&amp;#160; objects redirects &lt;strong&gt;all &lt;/strong&gt;relevant calls(I'll explain what &amp;quot;relevant&amp;quot; means in a second) to the fake object which you have created.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;strong&gt;Duck Typing Awesomeness&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Another cool thing about it is that &amp;quot;Duck&amp;quot; and &amp;quot;Dog&amp;quot; don't have to have a shared interface or base class. The &amp;quot;Swap&amp;quot; feature will redirect a method call if it exists on the &amp;quot;fake&amp;quot; object, but if it does not, it will invoke the original object. This is one interpretation of what's called &amp;quot;&lt;a href="http://haacked.com/archive/2007/08/19/why-duck-typing-matters-to-c-developers.aspx"&gt;Duck Typing&lt;/a&gt;&amp;quot;.&lt;/p&gt;  &lt;p&gt;The &amp;quot;CallsOn&amp;quot; and &amp;quot;WithCallsTo&amp;quot; methods take an object type, so you can send in anything you want.&amp;#160; if a method on the fake object matches the signature and name of a called method on the real object, the fake method will be invoked.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6716046" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/rosherove/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Art+Of+Unit+Testing/default.aspx">Art Of Unit Testing</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/Typemock/default.aspx">Typemock</category><category domain="http://weblogs.asp.net/rosherove/archive/tags/FeatureFocus/default.aspx">FeatureFocus</category></item></channel></rss>
