<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" 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/"><channel><title>Progressive Development : test-driven development</title><link>http://blogs.msdn.com/progressive_development/archive/tags/test-driven+development/default.aspx</link><description>Tags: test-driven development</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Motley says: "The only thing I'm going to mock is you"</title><link>http://blogs.msdn.com/progressive_development/archive/2007/08/07/motley-says-the-only-thing-i-m-going-to-mock-is-you.aspx</link><pubDate>Tue, 07 Aug 2007 20:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4273455</guid><dc:creator>James Waletzky</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/progressive_development/comments/4273455.aspx</comments><wfw:commentRss>http://blogs.msdn.com/progressive_development/commentrss.aspx?PostID=4273455</wfw:commentRss><description>&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Summary&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I can't mock something that I have no control over (like third-party or old legacy code)&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Design to interfaces, create a wrapper, and use tools for mocking. These are all great practices for leveraging mock objects.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;[Context:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Motley is struggling with creating mock objects for his unit tests]&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Arrrrggggghhhh. You know, I'm really trying to do this TDD thing but it is quickly becoming a real pain in the butt. You said that tests have to execute quick. Trust me, I totally believe you on that front. I'm doing my best to make them execute quickly but some things just are not made to mock.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: What's the problem? &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I'm interfacing with Marty's code. I "new" the object up and call it. Unfortunately Marty's stuff takes quite a few seconds to execute. It's making my TDD experience as painful as looking at that shirt you're wearing.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: What's wrong with my shirt? Anyway, the problem is that you are hard coding the instance creation of Marty's object. You are depending on an implementation, which is a violation of one of our key design principles we talked about.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Yeah, yeah, design to interfaces. But Marty has defined the interface and I have no control over it. No stubbing here, bubba!&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Ah, but you do have some control! The best thing to do would be to collaborate with Marty and get him to expose a well-defined and documented public interface to his component. Then you can simply couple yourself to the interface and not the implementation.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Right! Then I can plug and play different implementations of the component, replacing Marty's version with my own stub.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: You betcha! You got it, Mot! &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: But let's say Marty's component is actually a third party component that I have no control over.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: You can solve &lt;SPAN style="FONT-STYLE: italic"&gt;any&lt;/SPAN&gt; software problem with an extra layer of indirection. I'm kidding of course, but it does help here. In this case, wrap that component with a façade design pattern that provides an interface that you define. Then your core code depends on that façade interface instead of directly on the third party component. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Ok, fortunately that makes sense. You used the word "mock" previously but it just seems like a stub to me. What is the difference?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Don't worry too much about the nomenclature. A stub provides some sort of canned response to a call. Usually the response is hard-coded and there is no real logic associated with the result that is returned. A mock is similar to a stub, but it also verifies some kind of behavior. Did the client of the mock call it appropriately? Is the state of the object as we expect? Are return values from methods that we expected to be called set appropriately? The term "mock" goes along with TDD quite frequently, but you can get by effectively just using a stub if you wish.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: So a mock does extra work on top of a stub. How do I get the mock to do this extra work of behavior verification? Do I have to write all the code myself?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: You can, but you can also use a mock object framework. There are a few out on the Internet for various platforms. NMock is an example for .NET, but they're out there for other languages too. Generally the name is xMock, where the "x" is replaced by some kind of letter or phrase corresponding to the language or platform for which it is built.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I'm still not sold - what about all the wrappers I'll have to write to mock out bits of legacy code that were not designed with interfaces in mind?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Check out a free tool called &lt;A href="http://www.typemock.com/"&gt;TypeMock.NET&lt;/A&gt;. TypeMock allows you to mock &lt;SPAN style="FONT-STYLE: italic"&gt;any&lt;/SPAN&gt; class in your system, including concrete classes. No changes are required to the production code. TypeMock automatically intercepts calls to the class(es) of your choosing and injects whatever behavior you specify in its place. It does this in one of two ways: (a) by recording expectations of the code in a similar way that you would record a macro; and (b) using reflection to look for calls to expected methods and replace them with alternatives. The key is running an executable that wraps your test harness such that it is able to hook the desired method calls.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Holy crap - that sounds incredibly cool! &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: About as cool as you are, with all the windows open in the winter.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Ouch. A dig from Mave. Actually, the only thing you have dug is your grave once we leave the office and I get my hands on you. In all seriousness, I can understand the mock story, but I'm still not sure about the best technique for mocking something out. I figured I would just hack in an "if" statement to give me the right object given the scenario - release or test.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Good question. A hacked-in hook could work, but it's not the best option. Why don't we go over some methods of injecting mock objects into your design. Let's go write some code on the whiteboard...&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Pointer:&lt;/SPAN&gt; To take advantage of the full power of mock objects, try a mock object framework like &lt;A href="http://nmock.sourceforge.net/quickstart.html"&gt;NMock&lt;/A&gt;. The Quickstart documentation for NMock contains a simple example of how to use the framework and what is meant by behavior verification.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Resources:&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.375in; DIRECTION: ltr; unicode-bidi: embed" type=circle&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;A href="http://www.martinfowler.com/articles/mocksArentStubs.html"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Mocks Aren't Stubs&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;, by Martin Fowler;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;A href="http://www.typemock.com/"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;TypeMock.Net&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Working Effectively with Legacy Code&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;, by Michael Feathers, Prentice Hall PTR, ISBN: 0131177052, Sept. 2004.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=4273455" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/progressive_development/archive/tags/mock+objects/default.aspx">mock objects</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/test-driven+development/default.aspx">test-driven development</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/TDD/default.aspx">TDD</category></item><item><title>Motley says: "Refactoring means no more up-front design"</title><link>http://blogs.msdn.com/progressive_development/archive/2007/07/10/motley-says-refactoring-means-no-more-up-front-design.aspx</link><pubDate>Tue, 10 Jul 2007 18:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3793910</guid><dc:creator>James Waletzky</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/progressive_development/comments/3793910.aspx</comments><wfw:commentRss>http://blogs.msdn.com/progressive_development/commentrss.aspx?PostID=3793910</wfw:commentRss><description>&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Summary&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Refactoring keeps my design clean from the start, so no more up-front design!&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Up-front design is still necessary to achieve clarity on the overall approach (preventing rework later) and needs to be documented to allow others to review your thinking.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;[Context:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Motley is trying to educating himself on agile development and is reflecting on some reading with Maven]&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: This is really cool - I've been doing some reading on agile development and because I am doing refactoring continuously, that means I can do away with all that up-front design stuff we used to do.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Do away with it? Hardly! Maybe for a small couple-hundred line program, but any bigger than that, there is still value in thinking through the problem before you code anything - at least, if you want to prevent major rework later in the cycle when mistakes are more costly to fix.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: But refactoring is going to keep my design clean. What's the point of all the up-front thinking?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: That's true - refactoring helps you continuously keep quality high. However, if you make an investment in a bad high-level design and architecture, it becomes extremely hard to refactor yourself out of it. Then you are talking about reengineering, which can be a huge task. Refactoring is for small design changes without changing external functionality. Large changes are not as well suited to refactoring as it may lead to drastically changing the way requirements are implemented.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: But I want my design to &lt;SPAN style="FONT-STYLE: italic"&gt;emerge&lt;/SPAN&gt; based on the learning I get while coding!&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: You want the &lt;SPAN style="FONT-STYLE: italic"&gt;details&lt;/SPAN&gt; to emerge, but you need clarity on the overall approach before you flesh out the detail. A design phase is needed to understand the problem, investigate various high-level solutions and their trade-offs, and document your overall approach.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I'm not sure I buy that - the &lt;A href="http://www.agilemanifesto.org/" mce_href="http://www.agilemanifesto.org/"&gt;agile manifesto&lt;/A&gt; states that we should favor "working software over comprehensive documentation." No design document needed!&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Not exactly. You stated the keyword: &lt;SPAN style="FONT-STYLE: italic"&gt;favor&lt;/SPAN&gt;. It does not say there is no need for documentation whatsoever. We need that documentation to keep the stakeholders in our design happy and to provide something concrete for people to review.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: And I thought I was done with 100 page design documents…&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: You are! You want to document "just enough" in your design. Documents of 100 pages in length are generally overkill and violate the lean principles we talked about previously.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: But how do I know what is "just enough"? If I have 3 days on my schedule for design, "just enough" usually just means I hit the end of day 3.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Let's save that for another conversation. I have a great way to measure "just enough", but I am going to leave you in suspense. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Fine. I don't want to be here all day anyway.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Of course, the other topic of interest is once you have "just enough", you want your design to be "good".&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Great. I want "just enough" - I have no idea what that really means - and I want it to be "good" - I have no idea what that really means either. Judging "good" on a design is all in the eye of the beholder.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: You're comparing judging a design for "goodness" to judging looks?? Hah. Fortunately, we can get a little more scientific than that and focus on the principles that generally make one design better than another. Let's do that...&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Pointer:&lt;/SPAN&gt; Be careful with the term "emergent design". Many developers equate the phrase "emergent" design with jumping into Visual Studio and coding. What "emerges" at the end is some kind of design (usually junk). Truly "emergent design" uses a feedback technique to provide you continuous confirmation that you have a clean and working design. An example of an emergent design technique is test-driven development (TDD). Tests drive your design, refactoring keeps it clean, and test automation validates it all works.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Resources:&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://www.agilemanifesto.org/" mce_href="http://www.agilemanifesto.org/"&gt;Agile Development Manifesto&lt;/A&gt;, &lt;A href="http://en.wikipedia.org/wiki/Continuous_design" mce_href="http://en.wikipedia.org/wiki/Continuous_design"&gt;Wikipedia entry on Continuous Design&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3793910" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/progressive_development/archive/tags/test-driven+development/default.aspx">test-driven development</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/refactoring/default.aspx">refactoring</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/TDD/default.aspx">TDD</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/design/default.aspx">design</category></item><item><title>Motley says: "Test both private and public methods"</title><link>http://blogs.msdn.com/progressive_development/archive/2007/06/12/motley-says-test-both-private-and-public-methods.aspx</link><pubDate>Tue, 12 Jun 2007 10:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3108715</guid><dc:creator>James Waletzky</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/progressive_development/comments/3108715.aspx</comments><wfw:commentRss>http://blogs.msdn.com/progressive_development/commentrss.aspx?PostID=3108715</wfw:commentRss><description>&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Summary&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: To get high code coverage, we should be testing &lt;SPAN style="FONT-STYLE: italic"&gt;both&lt;/SPAN&gt; public and private methods&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Only test public methods. Testing private methods gets in the way of refactoring&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;[Context:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Maven checks in on Motley's unit testing practices and notices something odd]&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Hey Mot - how is the unit testing thing going?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Pretty good, I must say. I'm leveraging Test-Driven Development (TDD) as much as possible and it has really improved my code coverage. Check out all these tests!&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Wow - that is pretty good! In fact, that's more tests than I was expecting. Are you literally testing everything?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: You betcha. I have test cases around every method I write.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Even the private methods?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Duh. Of course! I gotta get that 100% code coverage, man! That was your idea don't forget.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Okay, I am willing to bet you are doing TDD &lt;SPAN style="FONT-STYLE: italic"&gt;without &lt;/SPAN&gt;the refactoring part of the process. Am I right?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Well, um, I guess. I'm trying to do a bit but it's such a pain in the butt. But wait, how can you tell just by looking at my tests???&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Well, if you are testing private methods that typically leads to a slightly larger number of tests, because a good practice is one test (or more) per method that you are testing. If you just test public methods, you can typically get the same code coverage with a slightly lower number of tests.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: So what? So I have a few more tests. It doesn't harm anything.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Ah, but it does. Testing private methods makes it really hard to refactor. You see, refactoring&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;does not usually affect a public interface but instead the implementation behind that interface, i.e. the private methods. With TDD, you need to be free to refactor, or you defeat one of its primary purposes - to drive a better design. If you need to update tests every time you make a refactoring change to your implementation because you are testing private methods directly, it really gets in the way and you are not going to do it. I am willing to bet that's why you are skipping an &lt;SPAN style="FONT-STYLE: italic"&gt;extremely important&lt;/SPAN&gt; part of the TDD process.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: The private methods do get in the way of refactoring, but code coverage is everything!&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: With TDD you don't write a line of code without having a test in place first. When you do refactoring, you rerun your tests to ensure you haven't broken anything. You should theoretically end up with the same coverage even just testing via public methods. If you can't hit your private methods through your public methods, why are they even there? Besides, the code coverage number in itself is not super interesting. What is more interesting is the analysis of why coverage numbers are low. This can lead you to more tests that you may otherwise miss. Don't go overboard trying to get to 100% - it's not worth it. Some C# language constructs, like foreach, have extra compiler-generated code in the intermediate language, which makes it real tough to get 100%. It's not worth the effort. Oh, and by the way, when I say "public", I typically also mean protected methods (public for subclasses) and even internal methods (public within the assembly).&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: So you're saying I should just test public methods and code coverage will just come if I use TDD. You're also saying that getting to that magical 100% code coverage number is often not worth the extra effort, and although code coverage is a good measure of your tests, the analysis is more important.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: You should write a book, Mot. I could not have put it better myself.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I'm a quick learner, as you can see from my stellar deliverables. I can even teach you a few things, like how to be likeable in a social atmosphere.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: What are you saying?!?&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Pointer:&lt;/SPAN&gt; You may ask, "How do I test private methods anyway? They are private!". In .NET, there are several ways to test private methods should you have a rare case where you definitely need to test a private:&lt;/P&gt;
&lt;UL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.375in; DIRECTION: ltr; unicode-bidi: embed" type=circle&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Leverage a test framework that uses reflection to call methods. The System.Reflection APIs can access private members of a class&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Use Visual Studio 2005 (and later) for unit testing. It will generate a test context object when you use the wizard to create a test that lets you access privates.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Create a friend assembly using the InternalsVisibleTo attribute that lets you access internal methods at least.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Create/Run a tool that flips some bits in the .NET assembly metadata to change the scope of classes and methods all to public (you are not testing the original compiled assembly in this case though).&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Create/Run a tool that generates a proxy for your class and accesses members via reflection. Your tests then use the proxy instead of the original class.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;Use preprocessor definitions to change the scope of the private methods to public in a special build.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Resources:&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://www.codeproject.com/csharp/TestNonPublicMembers.asp" mce_href="http://www.codeproject.com/csharp/TestNonPublicMembers.asp"&gt;How to Test Private and Protected Methods in .NET&lt;/A&gt; provides similar arguments for/against testing private methods, and talks about a subset of the above list for testing private methods.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3108715" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/progressive_development/archive/tags/unit+testing/default.aspx">unit testing</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/test-driven+development/default.aspx">test-driven development</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/refactoring/default.aspx">refactoring</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/TDD/default.aspx">TDD</category></item><item><title>Motley says: "I don't have time to Refactor - I need to get it right the first time"</title><link>http://blogs.msdn.com/progressive_development/archive/2007/04/19/motley-says-i-don-t-have-time-to-refactor-i-need-to-get-it-right-the-first-time.aspx</link><pubDate>Thu, 19 Apr 2007 16:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2170011</guid><dc:creator>James Waletzky</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/progressive_development/comments/2170011.aspx</comments><wfw:commentRss>http://blogs.msdn.com/progressive_development/commentrss.aspx?PostID=2170011</wfw:commentRss><description>&amp;nbsp; 
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Summary&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Refactoring takes too much time - I have to ship you know!&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Refactoring leads to much more maintainable code, and if you have tests in place, the return on investment far outweighs the cost.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;[Context: Motley has just embarked on his first adventures with TDD, but Maven wants to check-in to ensure Motley really understands the process]&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: So how are things going with TDD, Motley?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I've only been at this for a couple of hours - why are you bugging me already?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: It's good to start off on the right path. Just want to make sure you understand the TDD process.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Yeah, yeah, yeah. Write a failing test. Write code to pass it. Move on to the next requirement.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Whoa there, Nelly! You forgot one of the most important steps - refactoring.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Not really sure what you mean by that. If I have syntax errors I fix them. Duh.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Refactoring is all about improving the design of your code without changing any existing functionality. You mentioned previously that one of your values is writing great software. Well, refactoring is not just about writing it great the first time, it's about being realistic with yourself that you won't get it right the first time. You make the necessary changes to prevent it from starting just OK and turning into a big turd later as you maintain it. Obviously it takes more time than just writing the code once, but the pay-off down the road is huge.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: You've been sniffing too much glue, Maven. I barely have enough time to write my code once let alone keep redoing it over and over. I have to ship. If I don't ship, the business suffers, and most important, I get fired, and I suffer. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: What about when someone has to maintain that code moving forward? Do you want to make it difficult for them? How much do you think that costs the business?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Like everything in life, there is a trade-off. I have to do my best given that one shot is all I get. I vote ship and deal with maintenance issues later.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: That's what has gotten us into all this trouble with our legacy code! How do you like fixing bugs in all that old stuff?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Well… it sucks. Our legacy code is a "turd" - as you so eloquently put it.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Exactly. We need to make it easier for the next person to maintain. Refactoring is a way to get us there. Write your code, improve it, and then move forward with the next requirement. It's actually quite natural once you get in the rhythm. &lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: But I'm afraid that once I have it working that if I make changes I'll break something.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Ah, but you're doing TDD, right? That means you have tests in place so that if you do happen to break something you know about it right away. It's quite beautiful, really. Give it a shot and I'll check in with you later.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Why do I keep letting you do this to me? Fine, I'll try it. But if I'm late on my deliverables, it's your paycheck. Deal?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: I'm so confident that you're going to rock that yeah, I'll take that bet.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Pointer:&lt;/SPAN&gt; Many times the primary reason that developers are afraid to refactor isn't because they don't have the time, but because they don't have the confidence to make a change without breaking existing behavior. Having unit tests in place increases that confidence and makes refactoring easier and fun. Avoid refactoring without first having tests in place!&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Resources:&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE: italic"&gt;Refactoring: Improving the Design of Existing Code, &lt;/SPAN&gt;by Martin Fowler et al, Addison-Wesley Professional, ISBN: 0201485672, 1999.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2170011" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/progressive_development/archive/tags/unit+testing/default.aspx">unit testing</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/test-driven+development/default.aspx">test-driven development</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/refactoring/default.aspx">refactoring</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/TDD/default.aspx">TDD</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/legacy+code/default.aspx">legacy code</category></item><item><title>Motley says: "If I write code to pass tests I'm cheating!"</title><link>http://blogs.msdn.com/progressive_development/archive/2007/04/14/motley-says-if-i-write-code-to-pass-tests-i-m-cheating.aspx</link><pubDate>Sun, 15 Apr 2007 09:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2108449</guid><dc:creator>James Waletzky</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/progressive_development/comments/2108449.aspx</comments><wfw:commentRss>http://blogs.msdn.com/progressive_development/commentrss.aspx?PostID=2108449</wfw:commentRss><description>&amp;nbsp; 
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Summary&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Motley: &lt;/SPAN&gt;Tests need to validate code that has already been written - not the other way around.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Maven: &lt;/SPAN&gt;Writing&lt;SPAN style="FONT-WEIGHT: bold"&gt; &lt;/SPAN&gt;tests before you code allows the tests to drive your code while providing more sound requirements validation.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;[Context: Motley is thinking through test-driven development before he goes off and tries it]&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I've been thinking about this TDD thing and something is weird - if I write code to pass tests that's cheating! Tests need to validate code that has already been written.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Cheating? Hardly. Your tests are written around the requirements. What's wrong with writing code to execute the requirements? You're actually cheating if you write tests after the code. Now the tests are exercising the code but you are an extra step away from the requirements. Validation that you met the requirements is loose at best.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: But I write my application code to satisfy the requirements. What's the difference?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: The difference is that tests validate that the requirements are met, which is a logical layer between the requirements and the code. It forces you to think about the requirements in greater detail before implementing them. Plus, you get all the other benefits we talked about with TDD.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Well, maybe, but…&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Just do me a favor and try out TDD for a couple of days, okay?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Fine, fine, fine. If it gets you off my back. Give me a couple of days to play. Now go make yourself useful and clean up the kitchen or something.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Pointer:&lt;/SPAN&gt; "Requirements" as described in TDD are usually described at a lower level than you may be used to. A "requirement" is one small nugget of functionality that you want to implement. It may be an entire (simple) method, or one positive or negative path through the method.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Resources:&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE: italic"&gt;Test-Driven Development in Microsoft .NET&lt;/SPAN&gt;, by James Newkirk and Alexei Vorontsov, Microsoft Press, ISBN: 0735619484, 2004.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2108449" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/progressive_development/archive/tags/unit+testing/default.aspx">unit testing</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/test-driven+development/default.aspx">test-driven development</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/TDD/default.aspx">TDD</category></item><item><title>Motley says: "I can't write tests before application code - there's nothing to test."</title><link>http://blogs.msdn.com/progressive_development/archive/2007/04/09/motley-says-i-can-t-write-tests-before-application-code-there-s-nothing-to-test.aspx</link><pubDate>Mon, 09 Apr 2007 18:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2043868</guid><dc:creator>James Waletzky</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/progressive_development/comments/2043868.aspx</comments><wfw:commentRss>http://blogs.msdn.com/progressive_development/commentrss.aspx?PostID=2043868</wfw:commentRss><description>&lt;UL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.015in; DIRECTION: ltr; unicode-bidi: embed"&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri; TEXT-DECORATION: underline"&gt;Summary&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Motley: &lt;/SPAN&gt;You can't&lt;SPAN style="FONT-WEIGHT: bold"&gt; &lt;/SPAN&gt;possibly write tests before code - there's nothing to test.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Maven: &lt;/SPAN&gt;Writing tests for a method before coding it has all kinds of design advantages.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;[Context: Motley has been writing unit tests for a week. Maven wants to take the next step]&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Hey. Looks like you're getting pretty good at this unit testing thing.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Yeah, I can definitely see the benefits of having a thorough suite of tests. I can make sure that with every code change I don't break anything.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Want to take it even farther? Do you want to make an even bigger difference in quality?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: You really are a poop disturber, Maven. Fine. Let me hear about your hair-brained scheme.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: How about this? Try writing your tests first before you write your code. It's called test-driven development, or TDD for short.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I can't write tests before I write any code! There would be nothing to test! You've been sniffing to much glue for your own good.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: No, I am serious. Thinking about how you are going to test your code before you write it has all kinds of advantages, including driving your design. In fact, TDD is more of a design technique than a test technique when you really think about it.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: So how could this possibly drive my design? What difference would it make if I write my tests before my code - which still seems crazy to me - or after? It's like saying that I should edit my book before I write it.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Maybe if you thought more carefully about how your book was to be edited, you'd do a better job writing the book the first time. With TDD, since you write your tests first, your design automatically is testable, which the test team will love. You can also view your APIs from the perspective of a client even before the API is implemented, so you know right up front whether the API is usable. In addition, coupling and cohesion problems in your code come to light immediately. I am sure you hate programming to difficult APIs. Well, this way you make sure that your APIs are clean before you start because you are using them. TDD essentially forces a good design to emerge based on your tests.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: I'm still not sure about this. So all I have to do is write my tests before the code?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Well, to truly do TDD, here are the steps to follow:&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; FONT-SIZE: 11pt; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.375in; DIRECTION: ltr; FONT-FAMILY: Calibri; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=1&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Start with a requirement. &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: Calibri"&gt;A requirement could be one method you want to implement.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=2&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Write a test for that requirement.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=3&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Write just enough stub code to make the test and code compile.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=4&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Write just enough code to fail the test.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=5&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Execute your tests and watch them fail.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=6&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Write just enough code to pass the test.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=7&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Execute your tests and watch them pass.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=8&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Refactor.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=9&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Execute your tests to ensure you have not broken anything.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=10&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-STYLE: italic; FONT-FAMILY: Calibri"&gt;Go to step 1.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in 0in 0in 0.375in; FONT-STYLE: italic; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: That's a lot of steps. Seems too complicated to really be useful. And what's the point of writing a failing test first?&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Actually, it's not complicated. Once you get in the groove, it actually feels quite natural. Oh, and the point of writing a failing test is essentially to test your test. If you write a test and expect it to fail but it passes, you know you have a problem with either your test or your code. By starting with a failing case and then watching it pass, you are more confident that your test is good.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Let me finish what I am doing with my current set of modules and then maybe I'll give this a shot. No promises. You'll also have to enlighten me a bit on the refactoring step, as I'm not sure what to do there.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: No problem, Motley. I applaud you for having an open mind to try this stuff out.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Whatever. The boss says you were hired for your sound engineering ideas, so I guess I should humor him and listen. Hehehe. Kidding, of course. Maybe.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Maven: Stay tuned. I have a lot more to say about TDD. It's a great developer technique.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;Motley: Can't wait. Ugh.&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;______________________________&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Pointer:&lt;/SPAN&gt; A precursor to effectively doing test-driven development is understanding how to write good unit tests. Use a proven test framework to make it easy to write tests, and ensure your tests execute quickly. After all, with TDD, you are perpetually running your tests. It's such a great way to develop code that I don't think I'll ever go back to writing tests after code.&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri" mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 11pt; MARGIN: 0in; FONT-FAMILY: Calibri"&gt;&lt;SPAN style="FONT-WEIGHT: bold; COLOR: navy"&gt;Maven's Resources:&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="FONT-STYLE: italic"&gt;Test Driven Development: By Example, &lt;/SPAN&gt;by Kent Beck, Addison-Wesley, ISBN: 0321146530, 2002.&lt;/P&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2043868" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/progressive_development/archive/tags/unit+testing/default.aspx">unit testing</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/test/default.aspx">test</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/test-driven+development/default.aspx">test-driven development</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/refactoring/default.aspx">refactoring</category><category domain="http://blogs.msdn.com/progressive_development/archive/tags/TDD/default.aspx">TDD</category></item></channel></rss>