<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Udi Dahan - The Software Simplist &#187; TDD</title>
	<atom:link href="http://www.udidahan.com/category/tdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.udidahan.com</link>
	<description>Enterprise Development Expert &#38; SOA Specialist</description>
	<lastBuildDate>Sat, 24 Jul 2010 20:06:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>On Design for Testability</title>
		<link>http://www.udidahan.com/2010/04/18/on-design-for-testability/</link>
		<comments>http://www.udidahan.com/2010/04/18/on-design-for-testability/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 15:43:57 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[The Team]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/?p=1221</guid>
		<description><![CDATA[Almost at every conference, event, training, or consulting engagement someone asks for my opinion on the whole design for testability thing. I&#8217;m not quite sure why I haven&#8217;t blogged on this topic, especially at the time that a lot of the other bloggers were weighing in, but better late than never.
Before getting into that, I [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.udidahan.com/wp-content/uploads/elephant_balance.png" style="float:right; margin-left:10px; margin-bottom:10px; " alt="keeping balance" title="keeping balance" width="204" height="203" />Almost at every conference, event, training, or consulting engagement someone asks for my opinion on the whole design for testability thing. I&#8217;m not quite sure why I haven&#8217;t blogged on this topic, especially at the time that a lot of the other bloggers were weighing in, but better late than never.</p>
<p>Before getting into that, I want to start with a slightly broader scope of discussion.</p>
<p>You see, I get asked about &#8220;best practices&#8221; on all sorts of things. And I try not to be the kind of consultant that responds with &#8220;it depends&#8221;, but the context of the question often makes the answer irrelevant. And the unspoken context of a best-practice question is:</p>
<h2>Given infinite time and budget</h2>
<p>The biggest problem that I see with well-intentioned, best-practices-following developers and architects is that they <b>don&#8217;t</b> ask the question &#8220;is this the right thing for us to be focusing on right now?&#8221; Understandably, that is a difficult question to answer &#8211; but it needs to be asked, since you don&#8217;t have infinite time or budget to do everything according to best practices (assuming those even exist).</p>
<h2>About testing</h2>
<p>The biggest issue I have with the &#8220;design for testability&#8221; topic is the extremely narrow view it takes of the word &#8220;testability&#8221;, usually in the form of more code written by a developer which invokes the production code of the system, also known as &#8220;unit tests&#8221;.</p>
<p>There are many different kinds of testing &#8211; unit, integration, functional, load, performance, exploratory, etc&#8230; where some may be automated and others not. Should we not discuss what &#8220;design for testability&#8221; means for not-just-unit-testing?</p>
<h2>And what&#8217;s the point of testing anyway?</h2>
<p>It&#8217;s not to find bugs.</p>
<p>Research has shown that testing (of all kinds) is not the most effective way of finding bugs. I don&#8217;t have the reference handy but I&#8217;m pretty sure that it&#8217;s from <a href="http://alistair.cockburn.us/">Alistair Cockburn&#8217;s work</a>. Code reviews are (on average) about 60% more effective.</p>
<p>Don&#8217;t get me wrong &#8211; testing can provide indications that the software <b>has</b> bugs in it, but not necessarily where in the code those bugs are.</p>
<p>The purpose of testing is to provide quantitative and qualitative information about the system that can help various stakeholders in their decision-making processes. The relevance of that information indicates the quality of the testing. Here are some examples:</p>
<ul>
<li>The system supports 100 concurrent users, with the expected user-type distribution (X% role A, Y% role B, etc), performing expected use-case distributions, and collaboration scenarios.</li>
<li>Time to proficiency for new users in role A is expected to be 3 days</li>
<li>Alternate #2 of use case #12 fails on step #3</li>
</ul>
<p>As you can see, the relevance of the above information is dependent on what decisions the various stakeholders need to make. The bullet on load can help us decide if more machines are needed or if developers need to tune the performance of the systems. The bullet on time to proficiency can help us decide if larger investment in usability is required. Information like the last bullet can be used in conjunction with the first two to decide on the timing and type of a release.</p>
<p>The timeliness of this relevant information is critical to the success of a project.</p>
<p>Choosing which and how much of the various testing activities to perform when is something that needs to be revisited several times throughout the lifetime of a project, taking into account the current risks (threats and probabilities) and time and resource investment to mitigate them.</p>
<p>Let me reiterate &#8211; we&#8217;re not going to have enough time to do everything.</p>
<h2>On iterations</h2>
<p>If the only part of your organization that is doing iterations are your developers, you&#8217;re not agile.</p>
<p>In order to capitalize on the information that testers are providing, you need them in your iterations.</p>
<p>The same goes for the other roles involved in the project &#8211; business analysts, DBAs, sysadmins, etc.</p>
<p>I know that 99% of organizations aren&#8217;t structured in a way to do this.</p>
<p>I never said doing this would be easy.</p>
<h2>On design</h2>
<p>Figuring out what kind of design and how much to do when is just as important, and just as hard. Design for testability is one part of that, but not the only one, or necessarily the most important one at any point of time.</p>
<p>Within that design for testability topic is the &#8220;design for unit-testing&#8221; sub-topic which seems to be the popular one. Before getting into the design aspects of it, let&#8217;s take a closer look at the unit-testing side of things.</p>
<h2>On unit-testing</h2>
<p>The assumption is that having more unit tests will lead to a code-base with less bugs, thus requiring shorter time to get the system into production, which will pay back the time it took to write those unit tests to begin with.</p>
<p>In practice, what tends to happen is that as development progresses, testing code breaks as the structure of the production code changes. Now one of two things happens &#8211; either the testing code is removed or rewritten. In either case, we didn&#8217;t get the return on investment we expected on the first bit of testing code. Unfortunately, rare is the case where the relevant people in the organization understand <b>why</b>, resulting in the same situation repeating itself over and over again.</p>
<p>Those projects would have been better off without unit testing, though the organization as a whole might have used those experiences to learn and improve. It&#8217;s been my experience that if the organization wasn&#8217;t conscious enough in the context of the project to notice the situation, it is unlikely to do so at higher levels.</p>
<h2>On fragile unit tests</h2>
<p>The reason that a unit test ends up being rewritten (or removed) is that its code was coupled to the production code in such a way that it broke when the production code changed. This tendency to break (fragility) is a critical property of a unit test. A fragile unit test will slow down a developer doing work on some existing code &#8211; it actually makes the system less maintainable.</p>
<p>For a unit test code to be stable (not fragile) it needs to be coupled to stable properties of the production code. The question of whether the production code is designed in such a way that it has stable properties &#8211; is a design question. Is it a <b>unit</b>? If not, you will <b>not</b> be able to write a unit-test against it.</p>
<p>And anyway, who said that every class is a unit, or should be a unit? Domain models (when done right) are good examples of a unit, yet the classes that make them up may not be units. Unit-testing should only be attempted with things which are units. </p>
<p>I think too much weight is put on whether a dependency of a class is a concrete or interface type, and not nearly enough on the nature of the dependency. I wouldn&#8217;t blame the hammer for pounding my thumb, and by the same token I think that blame should not be directed towards tools like those from TypeMock.</p>
<h2>On tools</h2>
<p>There is so much more depth to both design and testability that needs to be more broadly understood. No tool has yet been created to handle either design or testing in such a way that humans can give up responsibility for the outcome. </p>
<p>Over the years I&#8217;ve noticed that tools are most significant when used by skilled practitioners, which makes sense in retrospect. Giving a novice carpenter a laser-guided saw probably won&#8217;t significantly change the outcome of their work. Ultimately, the skilled practitioners are the ones that create tools &#8211; not the novices. And no tool, no matter how advanced, will make a novice perform at levels like the skilled practitioner.</p>
<p>In the case of a project too big for a single skilled practitioner to complete in the time required (or at all), the balance of importance shifts away from tools to the project management topics described above.</p>
<h2>In summary</h2>
<p>I hope that this post has shed some light on the context in which decisions with respect to testing need to be made. Design is one activity that can support certain kinds of testing, but not the only one, or even the most important one for the given type of testing necessary at that time in the project.</p>
<p>Design is hard. Project management is hard. Testing is hard.</p>
<p>Getting the right mix of people that together have enough experience and skills in these activities isn&#8217;t easy.</p>
<p>Don&#8217;t expect that sprinkling some interfaces in your code base will be enough.<br />
That doesn&#8217;t count much in the way of design, just as writing code in a testing namespace doesn&#8217;t count much in the way of testability.</p>
<p>Looking forward to hearing your comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2010/04/18/on-design-for-testability/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>YAGNI &#8211; Once Bitten, Twice Shy?</title>
		<link>http://www.udidahan.com/2007/12/20/yagni-once-bitten-twice-shy/</link>
		<comments>http://www.udidahan.com/2007/12/20/yagni-once-bitten-twice-shy/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 22:23:22 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/12/20/yagni-once-bitten-twice-shy/</guid>
		<description><![CDATA[ It’s one of the things that sometimes drives me mad about the YAGNI philosophy of Agile. 
We need to stop throwing out the baby with the bath water.
Jay really liked that statement with relation to my previous post &#8220;Scalability &#8211; you wish you&#8217;re gonna need it&#8220;, so I thought I&#8217;d put up a logo [...]]]></description>
			<content:encoded><![CDATA[<p><em><img border="0" align="right" width="104" src="http://udidahan.weblogs.us/wp-content/uploads/yagni-once-bitten-twice-shy-thumb.png" alt="yagni_once_bitten_twice_shy" height="104" style="margin: 0px 20px 20px; border: 0px" /> It’s one of the things that sometimes drives me mad about the YAGNI philosophy of Agile. </em></p>
<p><em>We need to stop throwing out the baby with the bath water.</em></p>
<p>Jay really liked that statement with relation to my previous post &#8220;<a href="http://udidahan.weblogs.us/2007/12/12/scalability-you-wish-youre-gonna-need-it/">Scalability &#8211; you wish you&#8217;re gonna need it</a>&#8220;, so I thought I&#8217;d put up a logo for this movement. Anyone feeling like joining in, leave a comment, link, or whatever.</p>
<p>I understand that we don&#8217;t need to over-engineer everything, putting in every possible kind of extensibility point, so I accept that part of YAGNI. That is not a license to not think about the extensibility points you <strong>do</strong> need.</p>
<p>&lt;Remarks&gt;</p>
<p>This is a somewhat tongue-in-cheek post, and I do not want the pendulum to swing to far back the other way. But I do think it&#8217;s time it took a step back from the over-zealous &#8220;we&#8217;ll TDD our way there&#8221; thinking. Maybe Ron can pull it off. I&#8217;ve yet to see anyone else succeed.</p>
<p>&lt;/Remarks&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/12/20/yagni-once-bitten-twice-shy/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Performant and Explicit Domain Models</title>
		<link>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/</link>
		<comments>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/#comments</comments>
		<pubDate>Mon, 04 Jun 2007 20:31:34 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Business Rules]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/performant-and-explicit-domain-models/</guid>
		<description><![CDATA[Some Technical Difficulties

Ayende and I had an email conversation that started with me asking what would happen if I added an Order to a Customer’s &#8220;Orders&#8221; collection, when that collection was lazy loaded. My question was whether the addition of an element would result in NHibernate hitting the database to fill that collection. His answer [...]]]></description>
			<content:encoded><![CDATA[<h4>Some Technical Difficulties</h4>
<p style="padding: 0em 1em;">
Ayende and I had an email conversation that started with me asking what would happen if I added an Order to a Customer’s &#8220;Orders&#8221; collection, when that collection was lazy loaded. My question was whether the addition of an element would result in NHibernate hitting the database to fill that collection. His answer was a simple &#8220;yes&#8221;. In the case where a customer can have many (millions) of Orders, that’s just not a feasible solution. The technical solution was simple – just define the Orders collection on the Customer as &#8220;inverse=true&#8221;, and then to save a new Order, just write:
</p>
<div style="border: solid black 1px; padding: 0em 1em; background-color:beige; font-family:courier; ">session.Save( new Order(myCustomer) );</div>
<p style="padding: 0em 1em;">
Although it works, it’s not &#8220;DDD compliant&#8221; <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
<p style="padding: 0em 1em;">
In Ayende’s post <a href="http://ayende.com/Blog/archive/2007/05/29/Architecting-for-Performance.aspx">Architecting for Performance</a> he quoted a part of our email conversation.  The conclusion I reached was that in order to design performant domain models, you need to know the kinds of data volumes you’re dealing with. It affects both internals and the API of the model – when can you assume cascade, and when not. It’s important to make these kinds of things explicit in the Domain Model’s API.
</p>
<h4>How do you make &#8220;transparent persistence&#8221; explicit?</h4>
<p style="padding: 0em 1em;">
The problem occurs around &#8220;transparent persistence&#8221;. If we were to assume that the Customer object added the Order object to its Orders collection, then we wouldn’t have to explicitly save orders it creates, so we would write service layer code like this:
</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:600; font-family:courier">
using (IDBScope scope = this.DbServices.GetScope(TransactionOption.On))<br />
{<br />
	IOrderCreatingCustomer c = this.DbServices.Get&lt;IOrderCreatingCustomer&gt;(msg.CustomerId);<br />
	c.CreateOrder(message.OrderAmount);</p>
<p>	scope.Complete();<br />
}
</p></div>
<p style="padding: 0em 1em;">
On the other hand, if we designed our Domain Model around the million orders constraint, we would need to explicitly save the order, so we would write service layer code like this:
</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:600; font-family:courier">
using (IDBScope scope = this.DbServices.GetScope(TransactionOption.On))<br />
{<br />
	IOrderCreatingCustomer c = this.DbServices.Get&lt;IOrderCreatingCustomer&gt;(msg.CustomerId);<br />
	IOrder o = c.CreateOrder(message.OrderAmount);<br />
	this.DbServices.Save(o);</p>
<p>	scope.Complete();<br />
}
</p></div>
<p style="padding: 0em 1em;">
But the question remains, how do we communicate these guidelines to service layer developers from the Domain Model? There are a number of ways, but it’s important to decide on one and use it consistently. Performance and correctness require it.
</p>
<h4>Solution 1: Explicitness via Return Type</h4>
<p style="padding: 0em 1em;">
The first way is a little subtle, but you can do it with the return type of the &#8220;CreateOrder&#8221; method call. In the case where the Domain Model wishes to communicate that it handles transparent persistence by itself, have the method return &#8220;void&#8221;. Where the Domain Model wishes to communicate that it will not handle transparent persistence, have the method return the Order object created.
</p>
<p style="padding: 0em 1em;">
Another way to communicate the fact that an Order has been created that needs to be saved is with events. There are two sub-ways to do so:
</p>
<h4>Solution 2: Explicitness via Events on Domain Objects</h4>
<p style="padding: 0em 1em;">
The first is to just define the event on the customer object and have the service layer subscribe to it. It’s pretty clear that when the service layer receives a &#8220;OrderCreatedThatRequiresSaving&#8221; event, it should save the order passed in the event arguments.
</p>
<p style="padding: 0em 1em;">
The second realizes that the call to the customer object may come from some other domain object and that the service layer doesn’t necessarily know what can happen as the result of calling some method on the aggregate root. The change of state as the result of that method call may permeate the entire object graph. If each object in the graph raises its own events, its calling object will have to propagate that event to its parent – resulting in defining the same events  in multiple places, and each object being aware of all things possible with its great-grandchild objects. That is clearly bad.
</p>
<h4>What [ThreadStatic] is for</h4>
<p style="padding: 0em 1em;">
So, the solution is to use thread-static events.
</p>
<p style="padding: 0em 1em;">
[Sidebar] Thread-static events are just static events defined on a static class, where each event has the ThreadStaticAttribute applied to it. This attribute is important for server-side scenarios where multiple threads will be running through the Domain Model at the same time. The easiest thread-safe way to use static data is to apply the ThreadStaticAttribute.
</p>
<h4>Solution 3: Explicitness via Static Events</h4>
<p style="padding: 0em 1em;">
Each object raises the appropriate static event according to its logic. In our example, Customer would call:
</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; font-family:courier">
DomainModelEvents.RaiseOrderCreatedThatRequiresSavingEvent(newOrder);
</div>
<p style="padding: 0em 1em;">And the service layer would write:</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; font-family:courier">
DomainModelEvents.OrderCreatedThatRequiresSaving +=<br />
	delegate(object sender, OrderEventArgs e) { this.DbServices.Save(e.Order); };
</div>
<p style="padding: 0em 1em;">
The advantage of this solution is that it requires minimal knowledge of the Domain Model for the Service Layer to correctly work with it. It also communicates that anything that doesn’t raise an event will be persisted transparently behind the appropriate root object.
</p>
<h4>Statics and Testability</h4>
<p style="padding: 0em 1em;">
I know that many of you are wondering if I am really advocating the use of statics. The problem with most static classes is that they hurt testability because they are difficult to mock out. Often statics are used as Facades to hide some technological implementation detail. In this case, the static class is an inherent part of the Domain Model and does not serve as a Facade for anything.
</p>
<p style="padding: 0em 1em;">
When it comes to testing the Domain Model, we don’t have to mock anything out since the Domain Model is independent of all other concerns. This leaves us with unit testing at the single Domain Class level, which is pretty useless unless we’re TDD-ing the design of the Domain Model, in which case we’ll still be fiddling around with a bunch of classes at a time. Domain Models are best tested using State-Based Testing; get the objects into a given state, call a method on one of them, assert the resulting state. The static events don’t impede that kind of testing at all.
</p>
<h4>What if we used Injection instead of Statics?</h4>
<p style="padding: 0em 1em;">
Also, you’ll find that each Service Layer class will need to subscribe to all the Domain Model’s events, something that is easily handled by a base class. I will state that I have tried doing this without a static class, and injecting that singleton object into the Service Layer classes, and in that setter having them subscribe to its events. This was also pulled into a base class. The main difference was that the Dependency Injection solution required injecting that object into Domain Objects as well. Personally, I’m against injection for domain objects. So all in all, the static solution comes with less overhead than that based on injection.
</p>
<h4>Summary</h4>
<p style="padding: 0em 1em;">
In summary, beyond the &#8220;technical basics&#8221; of being aware of your data volumes and designing your Domain Model to handle each use case performantly, I’ve found these techniques useful for designing its API as well as communicating my intent around persistence transparency. So give it a try. I’d be grateful to hear your thoughts on the matter as well as what else you’ve found that works.
</p>
<p><u style="padding: 0em 1em;">Related posts:</u></p>
<ul style="padding: 0em 1em;">
<li>
<a href="http://udidahan.weblogs.us/2007/04/23/fetching-strategy-design/">Fetching Strategy Design</a> &#8211; showing how to separate the concern of eager loading from both your Domain Model and your Service Layer.
</li>
<li>
<a href="http://udidahan.weblogs.us/2007/03/06/better-domain-driven-design-implementation/">Better Domain-Driven Design Implementation</a> &#8211; showing the basics of how valuable interfaces between your Domain Model and the Service Layer can be.
</li>
<li>
<a href="http://udidahan.weblogs.us/2007/04/15/lazy-loading-and-how-messaging-fixes-everything-again/">Lazy Loading, and how messaging fixes everything again</a> &#8211; describing the advantage of O/R mapping your message classes as well.
</li>
<li>
<a href="http://udidahan.weblogs.us/2007/03/28/query-objects-vs-methods-on-a-repository/">Query Objects vs Methods on a Repository</a> &#8211; discussing the scalability (in terms of number of developers and queries) of Query Objects.
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/06/04/performant-and-explicit-domain-models/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Interfaces solve visibility and testing issues</title>
		<link>http://www.udidahan.com/2007/06/04/interfaces-solve-visibility-and-testing-issues/</link>
		<comments>http://www.udidahan.com/2007/06/04/interfaces-solve-visibility-and-testing-issues/#comments</comments>
		<pubDate>Mon, 04 Jun 2007 09:09:07 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/04/interfaces-solve-visibility-and-testing-issues/</guid>
		<description><![CDATA[Jimmy&#8217;s recent post called out some of the insights on the advantages of Ruby from Niclas&#8217; keynote at DevSummit 2007. Jimmy writes:

In Ruby it&#8217;s easy to redefine the visibility of a method from private to public for testing purposes. This was just one small detail in his talk of course, but I started to think [...]]]></description>
			<content:encoded><![CDATA[<p>Jimmy&#8217;s <a href="http://jimmynilsson.com/blog/posts/Devsummit2007b.htm">recent post</a> called out some of the insights on the advantages of Ruby from <a href="http://niclasnilsson.se/">Niclas&#8217; keynote at DevSummit 2007</a>. Jimmy writes:</p>
<blockquote><p>
In Ruby it&#8217;s easy to redefine the visibility of a method from private to public for testing purposes. This was just one small detail in his talk of course, but I started to think about how much pain I quite often go through regarding this in legacy code.
</p></blockquote>
<p>Let me just start out by saying that dealing with legacy code is far from easy. However, when writing new code, or as a part of refactoring that legacy, adding interfaces to your design can help you get around those visibility and testing issues.</p>
<p>For instance, if you only let &#8220;client&#8221; code access the interface, and not the implementation (probably using some kind of <a href="http://udidahan.weblogs.us/category/dependency-injection/">dependency injection</a>), then you could leave all sorts of methods public on your concrete class without worry that the client will call them since the interface doesn&#8217;t expose them. Now that the methods on the concrete class are public, you can easily test that class.</p>
<p>The way to package your code to make sure this occurs follows a <a href="http://udidahan.weblogs.us/2007/05/12/first-principle-of-design-refined/">very simple design principle</a>. This is much easier to put in practice on new development, but you&#8217;ll find that it isn&#8217;t that hard for legacy either. Since legacy code often doesn&#8217;t make use of interfaces, and the implementation is already packaged, and your new client code will already be separately packaged, you&#8217;re 90% there!</p>
<p>If you can change the legacy code, you&#8217;re actually 95% there. Just create a new package for the interface that the client code will use. Then change the legacy code to implement that interface &#8211; since the methods will be pretty much the same, it&#8217;s not that much work.</p>
<p>If you can&#8217;t change the legacy code, create a &#8220;wrapper&#8221; class that implements the interface and delegates the calls to the legacy code.</p>
<p>Finally, let me sum up by saying that I think Ruby is great. However, I think that often many advantages are attributed to anything new that may have already been possible/easy with what we already have today. Sometimes, the new stuff helps raise awareness on important issues &#8211; and then we can have great discussions on how to solve those issues with today&#8217;s (yesterday&#8217;s ?) technology <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/06/04/interfaces-solve-visibility-and-testing-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Domain Model Pattern</title>
		<link>http://www.udidahan.com/2007/04/21/domain-model-pattern/</link>
		<comments>http://www.udidahan.com/2007/04/21/domain-model-pattern/#comments</comments>
		<pubDate>Sat, 21 Apr 2007 14:53:38 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Business Rules]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[DataSets]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/04/21/domain-model-pattern/</guid>
		<description><![CDATA[When implementing a domain model, often object-relational mapping technologies are used. Like many tools, with their use comes the danger of abuse &#8211; abuse to the point of invalidating the benefits of the pattern itself.
From some pointers about how to use (and not to use) these tools, see why object-relational mapping sucks.
Martin Fowler&#8217;s has this [...]]]></description>
			<content:encoded><![CDATA[<p>When implementing a domain model, often object-relational mapping technologies are used. Like many tools, with their use comes the danger of abuse &#8211; abuse to the point of invalidating the benefits of the pattern itself.</p>
<p>From some pointers about how to use (and not to use) these tools, see <a href="http://udidahan.weblogs.us/2008/06/25/object-relational-mapping-sucks/">why object-relational mapping sucks</a>.</p>
<p>Martin Fowler&#8217;s has this to say about the <a href="http://martinfowler.com/eaaCatalog/domainModel.html">Domain Model Pattern</a>:</p>
<blockquote><p>
At its worst business logic can be very complex. Rules and logic describe many different cases and slants of behavior, and it&#8217;s this complexity that objects were designed to work with. A Domain Model creates a web of interconnected objects, where each object represents some meaningful individual, whether as large as a corporation or as small as a single line on an order form.
</p></blockquote>
<p>In short, using <a href="http://udidahan.weblogs.us/category/oo/">Object-Oriented techniques</a> to handle the complexity.</p>
<p>A more comprehensive discussion about what happens when it is not used can be found under the <a href="http://www.martinfowler.com/bliki/AnemicDomainModel.html">Anemic Domain Model Anti-Pattern</a>:</p>
<blockquote><p>
The basic symptom of an Anemic Domain Model is that at first blush it looks like the real thing. There are objects, many named after the nouns in the domain space, and these objects are connected with the rich relationships and structure that true domain models have. The catch comes when you look at the behavior, and you realize that there is very little behavior on these objects. Indeed often these models come with design rules that say that you are not to put any domain logic in the the domain objects. Instead there are a set of service objects which capture all the domain logic. These services live on top of the domain model and use the domain model for data.</p>
<p>The fundamental horror of this anti-pattern is that it&#8217;s so contrary to the basic idea of object-oriented design; which is to combine data and process together. The anemic domain model is really just a procedural style design&#8230;
</p></blockquote>
<p>In terms of <a href="http://udidahan.weblogs.us/category/ddd/">Domain-Driven Design</a>, this pattern is also known as Domain Layer.</p>
<p>Domain Models do a lot for encapsulating <a href="http://udidahan.weblogs.us/category/business-rules/">Business Rules</a>, thus making them amenable to automated testing. This hinges on keeping the Domain Model independent of things related to <a href="http://udidahan.weblogs.us/category/data-access/">Data Access</a>.</p>
<p>It is therefore almost required to use some kind of <a href="http://udidahan.weblogs.us/category/nhibernate/">Object/Relational Mapping</a> tool to make it possible to persist objects belonging to the domain model to databases and other kinds of storage.</p>
<p>The use of <a href="http://udidahan.weblogs.us/category/datasets/">DataSets</a> in .NET is often a sign of the Anemic Domain Model Anti-Pattern.</p>
<p>One thing to keep in mind when working on a domain model is that you probably won&#8217;t get it &#8220;right&#8221; the first time, and will have re-work the division of responsibility a couple of times. Techniques like <a href="http://udidahan.weblogs.us/category/tdd/">Test-Driven Development</a> help out immensely for that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/04/21/domain-model-pattern/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Self-Documenting, Test-Driven Alien Artifacts</title>
		<link>http://www.udidahan.com/2007/04/16/self-documenting-test-driven-alien-artifacts/</link>
		<comments>http://www.udidahan.com/2007/04/16/self-documenting-test-driven-alien-artifacts/#comments</comments>
		<pubDate>Mon, 16 Apr 2007 20:56:38 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Management]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/04/16/self-documenting-test-driven-alien-artifacts/</guid>
		<description><![CDATA[How much, and what kind of documentation do we need to create even if we have “self-documenting code”? Or is that kind of code enough all by itself? I for one yearn for the day where the code really will be enough, and I think that Scott and Ayende do too. First of all, I [...]]]></description>
			<content:encoded><![CDATA[<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>How much, and what kind of documentation do we need to create even if we have “self-documenting code”? Or is that kind of code enough all by itself? I for one yearn for the day where the code really will be enough, and I think that </FONT><A href="http://codebetter.com/blogs/scott.bellware/archive/2007/04/15/161874.aspx"><FONT face=Calibri>Scott</FONT></A><FONT face=Calibri> and </FONT><A href="http://ayende.com/Blog/archive/2007/04/16/Read-The-Code-is-not-a-valid-answer.aspx"><FONT face=Calibri>Ayende</FONT></A><FONT face=Calibri> do too. First of all, I think that as time progresses, the size of systems that the average developer works on is increasing substantially. And the larger a system is, the more we find a kind of code/design dialect that developers use to talk about that system. I think that these dialects are significantly different between framework/open source code, and application code. So, when a new developer comes in, do we tell them to “just read the code”? Or if the application has gone into production some time ago and now needs to be enhanced but the original team is long gone, what can be done?<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>What I usually suggest (and practice) is to have some kind of documentation explaining “language” of the system – what things go together, how, and why; and just as importantly, what things must be kept apart. This can be a Software Architecture and Design document, or even videos of the design sessions where things were first discussed. The relevant requirements should be a part of this as well. We need to know that the reason asynchronous messaging was used was for the strenuous scalability requirements, otherwise we might start adding the high-productivity Visual Studio Web Services we like so much.<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>Continuous integration is a boon to projects who use them. But developers who are only familiar with building solutions in Visual Studio may not be used to working that way, keeping code checked out for weeks at a time.<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><A href="http://codebetter.com/blogs/scott.bellware/archive/2007/04/15/161875.aspx"><FONT face=Calibri>Test-Driven Development and Architecture</FONT></A><FONT face=Calibri> will help those who know about it. We should probably write something up about how the system should be enhanced. Side-effect or not, developers and testers will need to know how we test the system – what tools are used in which way and at which stage of the development lifecycle. We could reference existing methodologies as well as in what ways we deviate from them and why.<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>What <I>sustainable</I> business value do we provide by leaving behind us </FONT><A href="http://www.eaves.org/blog-archive/000071.html"><FONT face=Calibri>alien artifacts and practices</FONT></A><FONT face=Calibri>? I’m not saying not to use state-of-the-art designs, techniques, and practices. On the contrary, I think that they are the key to sustainable business value. Necessary, but not sufficient. Documentation, of whatever flavor you find most suitable to each specific thing you are documenting, should be considered by the team as a whole, and the conclusions presented to stakeholders. The famous Chrysler C3 project’s long-term business value is shaky as the result of those stakeholders decision that documentation wasn’t necessary – in no way was the Agile process faulty in that respect.<o:p></o:p></FONT></SPAN></P><br />
<P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>Finally, you may be surprised the holes you find in your own thinking when forced to write down and explain to someone just coming in “how we do things around here”, I know I was. I can tell you that in the cases where I did that exercise, several stupid, costly mistakes were avoided. Fleshing out your thinking isn’t necessarily big design up front (BDUF), it’s just smart.<o:p></o:p></FONT></SPAN></P></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/04/16/self-documenting-test-driven-alien-artifacts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Paratechnological value</title>
		<link>http://www.udidahan.com/2007/03/06/paratechnological-value/</link>
		<comments>http://www.udidahan.com/2007/03/06/paratechnological-value/#comments</comments>
		<pubDate>Tue, 06 Mar 2007 09:28:23 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/archives/388</guid>
		<description><![CDATA[Technological churn &#8211; it&#8217;s a killer. It appears that as time goes by, the deluge just increases. I almost went into management because of it. Well, to be more precise, I do (kinda) manage, but I mean that I almost left the whole technology/engineering side of things. Luckily there&#8217;s more to software than that. Specifically [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">Technological churn &#8211; it&#8217;s a killer. It appears that as time goes by, the <a href="http://ayende.com/Blog/archive/2007/03/06/How-are-you-keeping-up-with-this-deluge-of-technology.aspx">deluge just increases</a>. I almost went into management because of it. Well, to be more precise, I do (kinda) manage, but I mean that I almost left the whole technology/engineering side of things. Luckily there&#8217;s more to software than that. Specifically the things around technology that aren&#8217;t technology dependent &#8211; paratechnological (from paralegal) if you will.</span></p>
<p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">The most interesting thing is that the knowledge investment you make in paratechnology has a (much) longer lifespan than that in technology directly. Those of us who have perfected our skills in VB6 found that .NET obseleted much of that. The same is true for Microsoft&#8217;s Web Service Enhancements, EJBs, etc. Even the languages themselves are changing substantially &#8211; as are their runtimes. However, object-orientation seems to be holding its own well into its 3rd decade. I suspect Domain-Driven Design (DDD) to enjoy a long life as well. </span><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">Beyond just being a lifetime issue, these paratechnological entities just seem to build on each other more and more. In order to understand higher order patterns, lower one need to be understood first. These patterns increase the scale of the problems that can be solved repeatably. </span></p>
<p></span><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">It has been my experience that those developers with similar experience-in-years, but only technological knowledge, are less productive than their peers with more paratechnological knowledge. I measure productivity in terms of number of feature points per unit of time. I understand that this is biased against infrastructure developers in application development teams &#8211; but I haven&#8217;t figured out how to measure them yet (at least, not well enough to say anything about it).</span></p>
<p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">Therefore, it is my thesis that developers should spend <em><span style="font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">at least</span></em> the same amount of time investing in paratechnological learning as technological learning. It is my suggestion that a 3-to-1 ratio would be even better &#8211; as in only a quarter of your time on technological study. I submit that the on-the-job work done with a given technology, including the figuring out how to do something that you haven&#8217;t done before, is enough. When I&#8217;m talking about &#8220;study&#8221;, I&#8217;m referring to courses, conferences, books read (not when looking sometime up). </span></p>
<p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">For me, the way that I find out (most) of what I need to know about a technology (not necessarily new), is to grill an expert on it. For instance, at TechEd Developers Barcelona 2006, I had the good fortune to sit with the <a href="http://ayende.com/Blog/archive/2007/03/06/How-are-you-keeping-up-with-this-deluge-of-technology.aspx">Workflow Foundation guys for at least an hour</a>, the WCF guys for about 3 hours total, WPF for half an hour, and the CAB guys for almost 4 hours &#8211; not all in one sitting <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Anyway, it was mostly me asking how to solve thorny issues I&#8217;m having difficulty with in my projects, and them trying to explain to me, in a way I&#8217;d understand, that most people don&#8217;t have my problems. Personally, I think that, if that&#8217;s true, &#8220;most people&#8221; just haven&#8217;t noticed yet <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  There were also numerous new ways of doing things that I didn&#8217;t consider to be an issue, so I tried to focus my learning on other things.</span></p>
<p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">And I guess that that&#8217;s my bottom line. When new technology comes along, you shouldn&#8217;t need to &#8220;start over&#8221;. The way that I design my systems, most technology is hidden away. WPF changes how my views are implemented &#8211; but that&#8217;s tucked behind an interface so that my supervising controllers don&#8217;t care. WCF changes how messages are transferred over the network, but that&#8217;s tucked away behind an &#8220;IBus&#8221; interface; message dispatch is also abstracted with &#8220;IMessageHandler&#8221; and &#8220;IMessage&#8221;. </span><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"> </span><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">By the way, I find WPF to be very interesting in improving the human-to-human interface between Human-Computer Interaction (HCI) professionals and developers. </span></p>
<p><span style="font-size: 11pt; font-family: 'Calibri','sans-serif'; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin">So&#8230; Invest wisely. Compound interest is your friend.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/03/06/paratechnological-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design &amp; Testability – Sense &amp; Sensibility</title>
		<link>http://www.udidahan.com/2007/03/04/design-testability-%e2%80%93-sense-sensibility/</link>
		<comments>http://www.udidahan.com/2007/03/04/design-testability-%e2%80%93-sense-sensibility/#comments</comments>
		<pubDate>Sun, 04 Mar 2007 23:44:00 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/archives/387</guid>
		<description><![CDATA[A discussion has been growing (primarily) between the Israeli bloggers Eli Lopian, Roy Osherove, and Ayende Rahien (aka Oren Eini) around the issue of OO design and testability. Mark Seemann quoted me on the topic (although I don’t quite remember saying it – but my memory isn’t what it used to be) so I guess [...]]]></description>
			<content:encoded><![CDATA[<p><span lang="EN-US"><font face="Calibri" size="3">A discussion has been growing (primarily) between the Israeli bloggers </font><a href="http://www.elilopian.com/2007/02/26/object-oriented-testable-designed-you-must-be-out-of-your-mind/"><font face="Calibri" size="3">Eli Lopian</font></a><font face="Calibri" size="3">, </font><a href="http://weblogs.asp.net/rosherove/archive/2007/02/25/why-you-should-think-about-ootp-object-oriented-testable-programming.aspx"><font face="Calibri" size="3">Roy Osherove</font></a><font face="Calibri" size="3">, and </font><a href="http://ayende.com/Blog/archive/2007/03/03/The-Production-Value-of-Seams.aspx"><font face="Calibri" size="3">Ayende Rahien</font></a><font face="Calibri" size="3"> (aka Oren Eini) around the issue of OO design and testability. Mark Seemann </font><a href="http://blogs.msdn.com/ploeh/archive/2007/02/28/ToodToop.aspx"><font face="Calibri" size="3">quoted</font></a><font size="3"><font face="Calibri"> me on the topic (although I don’t quite remember saying it – but my memory isn’t what it used to be) so I guess that I’m now compelled to join in.</font></font></span></p>
<p><span lang="EN-US" /><span lang="EN-US"><font face="Calibri" size="3">First of all, let me say that design does not necessarily begin and end with OO. The quality of a given design needs to be measured against both functional and non-functional requirements. Beyond the original OO, other principles have emerged that positively affect design – Arnon </font><a href="http://www.rgoarchitects.com/blog/PermaLink,guid,69ef2a86-2d59-4500-b328-0db29d8d0655.aspx"><font face="Calibri" size="3">blogged about these</font></a><font size="3"><font face="Calibri"> a while ago. The Single Responsibility Principle being one that keeps you thinking, “should that code go here?”. I also couldn’t design without leaning heavily on the Interface Segregation Principle and the Dependency Inversion Principle. Together with OO, I have found that these principles lead to more modular, flexible, loosely-coupled, and (yes) testable designs – all good things. Furthermore, we are continuing to uncover more areas where the original OO thinking does not serve us too well &#8211; distribution is a big one, so is persistence.</font></font></span></p>
<p><span lang="EN-US" /><span lang="EN-US"><font size="3"><font face="Calibri">On the topic of unit testing, it is OK to do state-based testing instead of directly calling methods on the class under test. I find this happening quite often with my “controller” classes which do most of their work in private event handlers. I could make those methods public for testability’s sake, not that it would change the design much since no other class interacts directly with the controller. I prefer to activate the controller as it would in production, and that’s by having my mocks raise events. The assertions I make are done upon the state the controller changes  &#8211; in my (mock) repository. I believe that this style of testing does nothing to compromise the “unit-ness” of the tests and addresses many of the points Eli brought up in his post.</font></font></span></p>
<p><span lang="EN-US" /><span lang="EN-US"><font size="3"><font face="Calibri">Anyway, that’s my 2 cents and I hope they make sense, and bring some down-to-earth sensibility to those wondering “are we asking the right question?”.<br />
</font></font></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/03/04/design-testability-%e2%80%93-sense-sensibility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software Testing for Developers Whitepaper</title>
		<link>http://www.udidahan.com/2006/11/15/software-testing-for-developers-whitepaper/</link>
		<comments>http://www.udidahan.com/2006/11/15/software-testing-for-developers-whitepaper/#comments</comments>
		<pubDate>Wed, 15 Nov 2006 17:44:37 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/349</guid>
		<description><![CDATA[After being invited to speak about Software Testing, as well as Software Version Control at the Prio Developers conference in Germany, I thought that I'd prepare for my presentation by first writing down how I learned about testing. This whitepaper is the result of that attempt and has been a great tool in getting the developers I work with to look at the world of software testing, as well as their own world from a new perspective.
<br/><br/>
<a href="http://udidahan.weblogs.us/archives/Software_Testing_for_Developers.pdf">Enjoy.</a>]]></description>
			<content:encoded><![CDATA[<p>After being invited to speak about Software Testing, as well as Software Version Control at the Prio Developers conference in Germany, I thought that I&#8217;d prepare for my presentation by first writing down how I learned about testing. This whitepaper is the result of that attempt and has been a great tool in getting the developers I work with to look at the world of software testing, as well as their own world from a new perspective.</p>
<p><a href="http://www.udidahan.com/wp-content/uploads/software_testing_for_developers.pdf">Enjoy.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2006/11/15/software-testing-for-developers-whitepaper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Behavior Specification, the next generation of unit testing</title>
		<link>http://www.udidahan.com/2006/05/06/behavior-specification-the-next-generation-of-unit-testing/</link>
		<comments>http://www.udidahan.com/2006/05/06/behavior-specification-the-next-generation-of-unit-testing/#comments</comments>
		<pubDate>Sat, 06 May 2006 23:28:48 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/281</guid>
		<description><![CDATA[After practicing unit testing for over two years, refactoring (as in with unit tests) for about the same, and TDD for over a year, I've finally found out how it really should be done. I'm working on an article that'll explain this in greater detail. The result is this:
<br/><br/>
Two assemblies, one for the interface, one for the implementation, "tests" go in the interface assembly. For example:
<br/><br/>
Interface project: Udi.Collections
<br/><br/>
File: IStack.cs
<br/><br/>
Content:<br/>
<pre>
public interface IStack
    {
        void Push(object o);
        object Pop();

        int Count { get; }
    }
</pre>
<br/><br/>
File: StackBehavior.cs
<br/><br/>
Content:<br/>
<pre>
public class StackBehavior : BehaviorSpecifier&#60;IStack&#62;
    {
        [Behavior]
        public void First()
        {
            int count = this.thing.Count;

            object o = 1;

            this.thing.Push(o);

            Assert.AreEqual(count + 1, this.thing.Count);

            object result = this.thing.Pop();

            Assert.AreEqual(o, result);
            Assert.AreEqual(count, this.thing.Count);
        }
    }
</pre>
<br/><br/>
Implementation Project: Udi.Collections.Implementation
<br/><br/>
File: Stack.cs
<br/><br/>
Content:<br/>
<pre>
public class Stack : IStack
    {
        #region IStack Members

        public void Push(object o)
        {
            list.Add(o);
        }

        public object Pop()
        {
            object result = list[list.Count - 1];
            list.RemoveAt(list.Count - 1);

            return result;
        }

        public int Count
        {
            get 
            { 
                return list.Count; 
            }
        }

        #endregion

        private IList&#60;object&#62; list = new List&#60;object&#62;();
    }
</pre>
<br/><br/>
***
<br/><br/>
Then, right click on the implementation project, and select 'Verify Behavior'. The results appear just like regular tests run with <a href="http://testdriven.net">TestDriven.net</a>.
<br/><br/>
Some reasons why this is better:
<br/><br/>
1. Tests (behaviors) are dependent only on the interface, which reduces the cases where developers will have to refactor test code as a result of implementation changes.<br/><br/>
2. Should a new implementation come along, we can reuse the tests already written with zero effort.
<br/><br/>
If you'd like to give this a try (using .net 2.0), leave me a comment and I'll send you the plugin for TestDriven.]]></description>
			<content:encoded><![CDATA[<p>After practicing unit testing for over two years, refactoring (as in with unit tests) for about the same, and TDD for over a year, I&#8217;ve finally found out how it really should be done. I&#8217;m working on an article that&#8217;ll explain this in greater detail. The result is this:</p>
<p>Two assemblies, one for the interface, one for the implementation, &#8220;tests&#8221; go in the interface assembly. For example:</p>
<p>Interface project: Udi.Collections</p>
<p>File: IStack.cs</p>
<p>Content:</p>
<pre>
public interface IStack
    {
        void Push(object o);
        object Pop();

        int Count { get; }
    }
</pre>
<p>File: StackBehavior.cs</p>
<p>Content:</p>
<pre>
public class StackBehavior : BehaviorSpecifier&lt;IStack&gt;
    {
        [Behavior]
        public void First()
        {
            int count = this.thing.Count;

            object o = 1;

            this.thing.Push(o);

            Assert.AreEqual(count + 1, this.thing.Count);

            object result = this.thing.Pop();

            Assert.AreEqual(o, result);
            Assert.AreEqual(count, this.thing.Count);
        }
    }
</pre>
<p>Implementation Project: Udi.Collections.Implementation</p>
<p>File: Stack.cs</p>
<p>Content:</p>
<pre>
public class Stack : IStack
    {
        #region IStack Members

        public void Push(object o)
        {
            list.Add(o);
        }

        public object Pop()
        {
            object result = list[list.Count - 1];
            list.RemoveAt(list.Count - 1);

            return result;
        }

        public int Count
        {
            get
            {
                return list.Count;
            }
        }

        #endregion

        private IList&lt;object&gt; list = new List&lt;object&gt;();
    }
</pre>
<p>***</p>
<p>Then, right click on the implementation project, and select &#8216;Verify Behavior&#8217;. The results appear just like regular tests run with <a href="http://testdriven.net">TestDriven.net</a>.</p>
<p>Some reasons why this is better:</p>
<p>1. Tests (behaviors) are dependent only on the interface, which reduces the cases where developers will have to refactor test code as a result of implementation changes.<br />
2. Should a new implementation come along, we can reuse the tests already written with zero effort.</p>
<p>If you&#8217;d like to give this a try (using .net 2.0), leave me a comment and I&#8217;ll send you the plugin for TestDriven.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2006/05/06/behavior-specification-the-next-generation-of-unit-testing/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Unit testing hardly free</title>
		<link>http://www.udidahan.com/2006/02/09/unit-testing-hardly-free/</link>
		<comments>http://www.udidahan.com/2006/02/09/unit-testing-hardly-free/#comments</comments>
		<pubDate>Fri, 10 Feb 2006 02:15:31 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/255</guid>
		<description><![CDATA[After reading Cory's <a href="http://www.cornetdesign.com/2006/01/unit-tests-are-free-in-tdd.html">"Unit tests are free in TDD"</a> I was reminded of a couple of our sessions in Cortina.
<br/><br/>
The first was about TDD and the GUI, hosted by <a href="http://xcskiwinn.org/community/blogs/panmanphil/default.aspx">Philip Nelson</a> where he set the tone by commenting on his experiences with MUCH decreased ROI when using TDD in the GUI. It was then that I began to feel that unit testing is really trying to be more than one thing.
<br/><br/>
(This isn't anything new, of course. From "unit tests", to "state-based tests", to "collaboration tests", going on to "integration tests" and "regression tests" we're writing the same style of code and running it with the same tools.)
<br/><br/>
It really hit home for me in the session I hosted with <a href="http://www.matshelander.com/Weblog/">Mats</a> about DI and IOC. When focusing on how DI changes the style of unit tests we write, <a href="http://www.developers.ie/blogs/cperrone/">Claudio</a> mentioned that the example tests I was writing when not using DI were really state-based, and not unit tests. At first I thought, "oh, I should change that", but after taking another look, I realized that I really REALLY liked the similarity of state-based test code and use-cases/stories.
<br/><br/>
I realized that state-based tests are a lot more robust to changes than classic white-box unit testing or collaboration testing. This prevents situations (like the one Philip presented) from occuring. Unit tests aren't free, or that close to it, for that matter. Anytime you're refactoring an implementation of a class, or the way it collaborates with other roles, but aren't changing its interface, state-based tests won't break - your run-of-the-mill unit tests probably will. I know mine always did.
<br/><br/>
The final point that brought it all together for me, in light of <a href="http://java.sys-con.com/author/2790North.htm">Dan's</a> thought-provoking Behavior-Driven-Development, was that state-based tests are really Behavior Specifications. 
<br/><br/>
"<b>This</b> is how this class should behave."
<br/><br/>
And then the light bulb went off over my head.
<br/><br/>
These state-based tests really should be able to run on any class that implements this interface.
<br/><br/>
In essence, these "tests" are as much a part of the interface as the actual interface declaration. The interface is really just a static declaration of capabilities, whereas the behavior specification is the dynamic one. Both of them belong together, in the production code...]]></description>
			<content:encoded><![CDATA[<p>After reading Cory&#8217;s <a href="http://www.cornetdesign.com/2006/01/unit-tests-are-free-in-tdd.html">&#8220;Unit tests are free in TDD&#8221;</a> I was reminded of a couple of our sessions in Cortina.</p>
<p>The first was about TDD and the GUI, hosted by <a href="http://xcskiwinn.org/community/blogs/panmanphil/default.aspx">Philip Nelson</a> where he set the tone by commenting on his experiences with MUCH decreased ROI when using TDD in the GUI. It was then that I began to feel that unit testing is really trying to be more than one thing.</p>
<p>(This isn&#8217;t anything new, of course. From &#8220;unit tests&#8221;, to &#8220;state-based tests&#8221;, to &#8220;collaboration tests&#8221;, going on to &#8220;integration tests&#8221; and &#8220;regression tests&#8221; we&#8217;re writing the same style of code and running it with the same tools.)</p>
<p>It really hit home for me in the session I hosted with <a href="http://www.matshelander.com/Weblog/">Mats</a> about DI and IOC. When focusing on how DI changes the style of unit tests we write, <a href="http://www.developers.ie/blogs/cperrone/">Claudio</a> mentioned that the example tests I was writing when not using DI were really state-based, and not unit tests. At first I thought, &#8220;oh, I should change that&#8221;, but after taking another look, I realized that I really REALLY liked the similarity of state-based test code and use-cases/stories.</p>
<p>I realized that state-based tests are a lot more robust to changes than classic white-box unit testing or collaboration testing. This prevents situations (like the one Philip presented) from occuring. Unit tests aren&#8217;t free, or that close to it, for that matter. Anytime you&#8217;re refactoring an implementation of a class, or the way it collaborates with other roles, but aren&#8217;t changing its interface, state-based tests won&#8217;t break &#8211; your run-of-the-mill unit tests probably will. I know mine always did.</p>
<p>The final point that brought it all together for me, in light of <a href="http://java.sys-con.com/author/2790North.htm">Dan&#8217;s</a> thought-provoking Behavior-Driven-Development, was that state-based tests are really Behavior Specifications. </p>
<p>&#8220;<b>This</b> is how this class should behave.&#8221;</p>
<p>And then the light bulb went off over my head.</p>
<p>These state-based tests really should be able to run on any class that implements this interface.</p>
<p>In essence, these &#8220;tests&#8221; are as much a part of the interface as the actual interface declaration. The interface is really just a static declaration of capabilities, whereas the behavior specification is the dynamic one. Both of them belong together, in the production code&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2006/02/09/unit-testing-hardly-free/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mocks, Interfaces, TDD, and the simplest thing</title>
		<link>http://www.udidahan.com/2005/01/22/mocks-interfaces-tdd-and-the-simplest-thing/</link>
		<comments>http://www.udidahan.com/2005/01/22/mocks-interfaces-tdd-and-the-simplest-thing/#comments</comments>
		<pubDate>Sun, 23 Jan 2005 03:34:46 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/165</guid>
		<description><![CDATA[I realized that I haven&#8217;t been very good at explaining why using mocks and interfaces doesn&#8217;t go against the simplest thing tenet. To those who haven&#8217;t agreed with me so far, when you start TDDing, do you originally separate your UI from your logic, and data access, or is it all together? I&#8217;m assuming you [...]]]></description>
			<content:encoded><![CDATA[<p>I realized that I haven&#8217;t been very good at explaining why using mocks and interfaces doesn&#8217;t go against the simplest thing tenet. To those who haven&#8217;t agreed with me so far, when you start TDDing, do you originally separate your UI from your logic, and data access, or is it all together? I&#8217;m assuming you do. By the same reasoning that you present against originally programming against an interface, it only makes sense to NOT separate your UI, BL, DAL, etc.</p>
<p>As it appears, most developers I&#8217;ve ever met who TDD do, in fact, separate their code into &#8220;layers&#8221;, and do not refactor their way there. In their experience, this idea of separating code of differing responsibilities has been proven valuable enough times to just start with it. No need to re-invent/discover the wheel using TDD.</p>
<p>By this logic, those who have stated programming to an interface violates the &#8220;simplest thing&#8221; principle do not believe that it has been proven valuable. In that case, I guess that the argument just becomes &#8220;I believe&#8221; versus &#8220;You believe&#8221; in which case, I concede the point. Just as most of us have reached the conclusion the TDD has been proven valuable, some of us believe that mocking is similar.</p>
<p>So, my only recourse is to beseech you to give it a try. It has served me SO well that I would <b>strongly </b>recommend it to <i>anyone </i>who TDDs. </p>
<p>See, I&#8217;ve bolded and italicized, so I MUST be right <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2005/01/22/mocks-interfaces-tdd-and-the-simplest-thing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple? Easy? Matters?</title>
		<link>http://www.udidahan.com/2005/01/09/simple-easy-matters/</link>
		<comments>http://www.udidahan.com/2005/01/09/simple-easy-matters/#comments</comments>
		<pubDate>Mon, 10 Jan 2005 03:56:39 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/154</guid>
		<description><![CDATA[Owen Rogers from Thoughtworks posts some thoughts on the meaning of &#8220;the simplest thing that could possibly work&#8221;. I think that the only thing that is really understood is that &#8220;simple isn&#8217;t easy&#8221; &#8211; we don&#8217;t have a metric that tells us when the code is &#8220;as simple as possible, but no simpler&#8221;, so we&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>Owen Rogers from Thoughtworks <a href="http://dotnetjunkies.com/WebLog/exortech/archive/2004/12/23/38468.aspx">posts</a> some thoughts on the meaning of &#8220;the simplest thing that could possibly work&#8221;. I think that the only thing that is really understood is that &#8220;simple isn&#8217;t easy&#8221; &#8211; we don&#8217;t have a metric that tells us when the code is &#8220;as simple as possible, but no simpler&#8221;, so we&#8217;re really on our own.</p>
<p>The good news is that it doesn&#8217;t really matter.</p>
<p>I can hear you all gasping.</p>
<p>The reason it doesn&#8217;t matter is that we don&#8217;t have to be 100% right the first time is because we&#8217;re going to be changing it over, and over, and over again. In fact, if we took the easy path &#8220;by mistake&#8221;, as we move along writing more tests, making them pass, refactoring, the code will &#8220;correct itself&#8221;. The same thing will happen if we stray from the one true path in any way.</p>
<p>The nice thing about the one true path is that you don&#8217;t have to be right on it. TDD and the XP tenets are rules of thumb that are like magnetic fields that push us back on the path when we stray a little too much.</p>
<p>Change is expected. Change is good. Change is what makes &#8220;the simplest thing that could possibly work&#8221;, in all it&#8217;s clear-as-mud-ness, really work, without forcing developers to agree ahead of time what it actually means.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2005/01/09/simple-easy-matters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More on Tests &amp; Interfaces</title>
		<link>http://www.udidahan.com/2005/01/07/more-on-tests-interfaces/</link>
		<comments>http://www.udidahan.com/2005/01/07/more-on-tests-interfaces/#comments</comments>
		<pubDate>Sat, 08 Jan 2005 04:14:13 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/153</guid>
		<description><![CDATA[While I usually don&#8217;t just link, I think that it&#8217;s late enough for me to allow myself this one slip &#8211; here.
]]></description>
			<content:encoded><![CDATA[<p>While I usually don&#8217;t just link, I think that it&#8217;s late enough for me to allow myself this one slip &#8211; <a href="http://patricklogan.blogspot.com/2005/01/testing-interfaces.html">here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2005/01/07/more-on-tests-interfaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Mock)Simple ain&#8217;t (Mock)easy</title>
		<link>http://www.udidahan.com/2005/01/05/mocksimple-aint-mockeasy/</link>
		<comments>http://www.udidahan.com/2005/01/05/mocksimple-aint-mockeasy/#comments</comments>
		<pubDate>Thu, 06 Jan 2005 03:31:02 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/150</guid>
		<description><![CDATA[Just the other day I was reading some blogs and ran into one stating something like: People often confuse simple with easy, simple is quite often difficult.
I&#8217;m posting this in response to comments on my previous post about mocking interfaces that stated that using interfaces early in development went against the XP tenet &#8220;do the [...]]]></description>
			<content:encoded><![CDATA[<p>Just the other day I was reading some blogs and ran into one stating something like: People often confuse simple with easy, simple is quite often difficult.<br />
I&#8217;m posting this in response to comments on my previous post about mocking interfaces that stated that using interfaces early in development went against the XP tenet &#8220;do the simplest thing that could work&#8221;. While I might agree that at the moment I realize that I need a class to do something, I might not right away make an interface, it would probably come soon after. The reason I say this is that a class usually has to interact with other classes. I prefer to formalize this interaction with an interface which acts as a contract between the two parties. Why do I do this? Because it gives me greater agility moving on. I am now able to change, or entirely replace, a given class without cascading changes to other classes as long as the interface is maintained.</p>
<p>You all know the pain of a large refactoring, not only is the production code changed, but lots of test code has to change too. Interfaces minimize that pain.</p>
<p>So, although working with interfaces is not the EASIEST thing to do, overall it is certainly the simplest. And, to tell you the truth, it&#8217;s not THAT big a deal, I mean, you&#8217;re already adding the methods to the class, why not add them to an interface as well, and make the &#8220;client&#8221; class depend on the interface instead? And about the whole &#8220;should an interface start with a big &#8216;I&#8217;&#8221; debate, it&#8217;s a coding convention issue &#8211; choose something and stick with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2005/01/05/mocksimple-aint-mockeasy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Legacy is such a nice word</title>
		<link>http://www.udidahan.com/2005/01/03/legacy-is-such-a-nice-word/</link>
		<comments>http://www.udidahan.com/2005/01/03/legacy-is-such-a-nice-word/#comments</comments>
		<pubDate>Tue, 04 Jan 2005 03:40:49 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/147</guid>
		<description><![CDATA[Legacy is such a nice word considering all the headaches is brings.
One of the classic problem cases in TDD/XP is how to approach a legacy code base that has no tests. Lots has been written about this topic, but I just wanted to talk about the bootstrap problem:
You&#8217;re afraid to make any changes to the [...]]]></description>
			<content:encoded><![CDATA[<p>Legacy is such a nice word considering all the headaches is brings.</p>
<p>One of the classic problem cases in TDD/XP is how to approach a legacy code base that has no tests. Lots has been written about this topic, but I just wanted to talk about the bootstrap problem:</p>
<p>You&#8217;re afraid to make any changes to the code without tests.<br />
How can you write unit tests for legacy code without changing it even the slightest bit &#8211; considering it wasn&#8217;t ever designed to be unit tested and is probably a big tangled mess.</p>
<p>The answer, as always, is more abstraction!</p>
<p>So you can&#8217;t write unit tests. Boo hoo. Get over it. Start by writing functional tests, use <a href="http://fit.c2.com/">FIT</a> or whatever else you like. Start at the outside and work your way in. </p>
<p>Once the functional tests are in place, you can start refactoring the design (I wouldn&#8217;t say) safely (but probably safer) into units that can then be unit tested.</p>
<p>Is it perfect? No. But its better than it was before.<br />
Will there be bugs because of the changes we made? Yes. We&#8217;ll just have to catch them later.</p>
<p>All this sounds like a lot of pain, and it is. But it&#8217;s nothing compare to not doing it. Do you really want to mess around with a whole bunch of code that worked before without something telling you if it&#8217;s still working after? I know I don&#8217;t.</p>
<p>Remember the tenet of XP called Courage? Legacy is a great place to work on it <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2005/01/03/legacy-is-such-a-nice-word/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mock Objects ? NO! Mock Interfaces!</title>
		<link>http://www.udidahan.com/2005/01/01/mock-objects-no-mock-interfaces/</link>
		<comments>http://www.udidahan.com/2005/01/01/mock-objects-no-mock-interfaces/#comments</comments>
		<pubDate>Sun, 02 Jan 2005 03:44:41 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/145</guid>
		<description><![CDATA[There has been some discussion recently in the TDD/Agile world about the cost/value tradeoff of using mock objects. To tell you the truth, I was surprised. Hearing about how mocks increase the complexity of the system, go against &#8220;doing the simplest thing&#8221;, etc, was rather unexpected.
First off, let&#8217;s set some context. We&#8217;re talking about software [...]]]></description>
			<content:encoded><![CDATA[<p>There has been some discussion recently in the TDD/Agile world about the cost/value tradeoff of using mock objects. To tell you the truth, I was surprised. Hearing about how mocks increase the complexity of the system, go against &#8220;doing the simplest thing&#8221;, etc, was rather unexpected.</p>
<p>First off, let&#8217;s set some context. We&#8217;re talking about software projects that require a team of developers (let&#8217;s say at least 2) a significant amount of time (let&#8217;s say at least 6 months) to develop. In these sizes of projects, TDD is undisputably cost effective. Now, before getting to the question of mocks, let&#8217;s just go back to a basic truth.</p>
<p>Code to an interface, not an implementation.</p>
<p>You&#8217;ve heard a million times. I know I have. It is generally considered a &#8220;best practice&#8221; &#8211; whatever those are. For my part, I try to follow this guidance as best I can. What it usually results in is a significant number of interfaces, with a not-so-slightly larger number of implementation classes. This is usually in the first iterations, slowly moving to a larger number of implementations to interfaces.</p>
<p>In these cases, implementation classes rarely are aware of each other. For the most part, they are only aware of interfaces.</p>
<p>Now, mock objects are just a way to get an object that implements an interface so that you can use it for testing. So, if you are testing a given class that depends on N interfaces, you will probably need to mock up an object for each one of those interfaces to thoroughly test the class.</p>
<p>So, my question is: What&#8217;s the big deal?</p>
<p>My answer: If you&#8217;ve already followed to above principle, mocks are just what you need, and require no rework at all to use. On the other hand, if you did NOT follow the &#8220;code to an interface &#8230;&#8221; principle, in order to use mock objects, you&#8217;ll have to do a lot of rework; amounting (pretty much) to changing your code to follow the &#8220;golden rule&#8221;.</p>
<p>If anything, mocks become a great canary. You won&#8217;t be able to use mocks (your canary will die) if you didn&#8217;t code to an interface. If you run into a case when you can&#8217;t mock, it&#8217;s a sign that the code needs to be cleaned up anyway. Don&#8217;t blame the canary for dying when it takes a whiff of your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2005/01/01/mock-objects-no-mock-interfaces/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Juval Lowy on TDD</title>
		<link>http://www.udidahan.com/2004/12/28/juval-lowy-on-tdd/</link>
		<comments>http://www.udidahan.com/2004/12/28/juval-lowy-on-tdd/#comments</comments>
		<pubDate>Wed, 29 Dec 2004 04:02:34 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/141</guid>
		<description><![CDATA[&#8220;Is there any other way to develop software?&#8221;
]]></description>
			<content:encoded><![CDATA[<p>&#8220;Is there any other way to develop software?&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/12/28/juval-lowy-on-tdd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Take a whiff&#8230;</title>
		<link>http://www.udidahan.com/2004/12/02/take-a-whiff/</link>
		<comments>http://www.udidahan.com/2004/12/02/take-a-whiff/#comments</comments>
		<pubDate>Thu, 02 Dec 2004 22:06:45 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/133</guid>
		<description><![CDATA[I just ran into a nice list of code smells one could forward to a co-worker to explain what kind of code smells there are, and possibly to get them to read Fowler&#8217;s Refactoring book.
]]></description>
			<content:encoded><![CDATA[<p>I just ran into <a href="http://www.soberit.hut.fi/mmantyla/BadCodeSmellsTaxonomy.htm">a nice list of code smells </a>one could forward to a co-worker to explain what kind of code smells there are, and possibly to get them to read Fowler&#8217;s Refactoring book.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/12/02/take-a-whiff/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mock a Unit</title>
		<link>http://www.udidahan.com/2004/11/04/mock-a-unit/</link>
		<comments>http://www.udidahan.com/2004/11/04/mock-a-unit/#comments</comments>
		<pubDate>Fri, 05 Nov 2004 03:07:49 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/127</guid>
		<description><![CDATA[A question was raised in the TestDrivenDevelopment discussion group about mock objects: &#8220;How would you differentiate between what you refer to as a &#8220;test implementation&#8221; compared to a mock?&#8221; I posted my response to the group, but after seeing how much this reflects on design, I thought I&#8217;d post it here too:
My understanding of TDD [...]]]></description>
			<content:encoded><![CDATA[<p>A question was raised in the TestDrivenDevelopment discussion group about mock objects: &#8220;How would you differentiate between what you refer to as a &#8220;test implementation&#8221; compared to a mock?&#8221; I posted my response to the group, but after seeing how much this reflects on design, I thought I&#8217;d post it here too:</p>
<p>My understanding of TDD and mocks is that mocks are used to keep the unit testing in and around the unit. What that means is that when I’m TDDing a class that uses another class, I don’t want the results of my tests to depend on whether or not the other class exists. Let’s look at an example to make this more concrete. Say I’m TDDing a Customer class, which has a property called IsPreferred. This property calculates the sum of all the customer’s orders this past year, and if the sum is larger than some value, returns true. So my test code might look like this:</p>
<p>[Test]<br />
public void IsPreferredCustomerShouldBeTrueWhenSumOfOrdersIsLargerThanX()<br />
{<br />
  Customer c = new Customer();<br />
  c.AddOrder( new Order(X) );<br />
  c.AddOrder( new Order(1) );</p>
<p>  Assert.IsTrue(c.IsPreferred);<br />
}</p>
<p>and the code itself might look like this:</p>
<p>public class Customer<br />
{<br />
  private List m_orders;<br />
  private double m_preferredOrderSum;</p>
<p>  public bool IsPreferred<br />
  {<br />
    get<br />
    {<br />
      double result;<br />
      foreach(Order o in m_orders)<br />
        result += o.Price;</p>
<p>      return ( result &gt; m_preferredOrderSum);<br />
    }<br />
  }</p>
<p>  public void AddOrder(Order o)<br />
  {<br />
    m_orders.Add(o);<br />
  }<br />
}</p>
<p>The problem with this is that in order for this code to work, I must already have an Order class. In essence, I’m not really unit testing here, I’m actually integration testing – and we all know that integration testing should come only once we’ve finished unit testing all the classes participating in the integration. So, we’ve got a slight problem here – there’s no way to test the Customer class without the Order class, or is there?</p>
<p>Suppose that we had an interface called IOrder, which has a property called Price. We could make the Customer class dependent on the interface instead of on the Order class implementation. IOrder would look something like:</p>
<p>public interface IOrder<br />
{<br />
  double Price { get; }<br />
}</p>
<p>and Customer would then change to:</p>
<p>public class Customer<br />
{<br />
  private List m_orders;<br />
  private double m_preferredOrderSum;</p>
<p>  public bool IsPreferred<br />
  {<br />
    get<br />
    {<br />
      double result;<br />
      foreach(IOrder o in m_orders)<br />
        result += o.Price;</p>
<p>      return ( result &gt; m_preferredOrderSum);<br />
    }<br />
  }</p>
<p>  public void AddOrder(IOrder o)<br />
  {<br />
    m_orders.Add(o);<br />
  }</p>
<p>}</p>
<p>And as a result, I no longer need to have the Order class at all in order to test the Customer class – all I need is something that implements IOrder. Mock objects are great for this, allowing us to quickly get an object that implements an interface without writing much code. This allows/forces me to change my test code to something like this (using NMock syntax):</p>
<p>[Test]<br />
public void IsPreferredCustomerShouldBeTrueWhenSumOfOrdersIsLargerThanX()<br />
{<br />
  Customer c = new Customer();<br />
  Mock firstOrder = new DynamicMock(typeof(IOrder));<br />
  Mock secondOrder = new DynamicMock(typeof(IOrder));</p>
<p>  firstOrder.Expect(“Price”); // expect that one call will be made to the property<br />
  secondOrder.Expect(“Price”); // expect that one call will be made to the property</p>
<p>  c.AddOrder( (IOrder)firstOrder.MockInstance);<br />
  c.AddOrder( (IOrder) secondOrder.MockInstance);</p>
<p>  c.IsPreferred; // this should perform one call to the Price property for each of the orders</p>
<p>  // verify that the expectations we set (that the Price property would be called once per Order) were fulfilled.<br />
  firstOrder.Verify();<br />
  secondOrder.Verify();<br />
}</p>
<p>So, what have we achieved? True unit testing. We are now able to test the Customer class as a unit, without depending on any concrete implementations of other classes. As you can see, my test code has changed considerably as a result, but is now independent of my Order class. This is a GOOD THING, since one of the problems I find when TDDing without mocks is that a change in the design of one class (Order for example) breaks tests for totally different classes (Customer for example). When TDDing, I’m always changing the designs of my classes, and having to fix tests that break is something that slows me down &#8211; mock objects decrease the friction.</p>
<p>Some have began calling this style of TDD – mock driven development or MDD, but I prefer to say that mocks are the thing that keeps the “unit” in the unit testing in TDD.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/11/04/mock-a-unit/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>TDD&#8217;s just like falling off a bike</title>
		<link>http://www.udidahan.com/2004/07/06/tdds-just-like-falling-off-a-bike/</link>
		<comments>http://www.udidahan.com/2004/07/06/tdds-just-like-falling-off-a-bike/#comments</comments>
		<pubDate>Wed, 07 Jul 2004 04:00:05 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/99</guid>
		<description><![CDATA[Another one&#8217;s infected: Don Park writes about his first experiences with TDD &#8211; &#8220;Test-Driven&#8220;. I think that this practice will soon reach critical mass. One day, not so far away, not doing TDD will be like not writing OO code.
What&#8217;s needed for this to happen are better tools &#8211; tools that will make TDD the [...]]]></description>
			<content:encoded><![CDATA[<p><P>Another one&#8217;s infected: Don Park writes about his first experiences with TDD &#8211; &#8220;<U><FONT color="#800080">Test-Driven</FONT></U>&#8220;. I think that this practice will soon reach critical mass. One day, not so far away, not doing TDD will be like not writing OO code.</P><br />
<P>What&#8217;s needed for this to happen are better tools &#8211; tools that will make TDD the point of lowest potential; meaning that things will just gravitate to it, naturally. Just as its easier to sit than to stand, so the tools will need make it easier to TDD than to keep doing things the way you&#8217;ve done them up until now. We&#8217;re not there yet, but in light of the &#8220;recent&#8221; backing of Microsoft in Visual Studio 2005, hopefully things will start to snowball.</P><br />
<P>TDD is the future, and the future is now. Embrace it.</P><br />
<P>&lt;aside&gt;I&#8217;ve always been told to end with a call to action, so that&#8217;s it <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  &lt;/aside&gt;</P></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/07/06/tdds-just-like-falling-off-a-bike/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wrangling over TDD with Leon</title>
		<link>http://www.udidahan.com/2004/07/05/wrangling-over-tdd-with-leon/</link>
		<comments>http://www.udidahan.com/2004/07/05/wrangling-over-tdd-with-leon/#comments</comments>
		<pubDate>Tue, 06 Jul 2004 05:14:20 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/98</guid>
		<description><![CDATA[This will be my last post for tonight, I swear  
During the break at the UG, I started chatting with Leon Langleyben&#160;(yes, it did take me 7 tries until I spelled that right) about TDD.
I stated that, as opposed to XP, TDD&#8217;s entry barrier would quite low and could still be quite effective. Leon [...]]]></description>
			<content:encoded><![CDATA[<p><P>This will be my last post for tonight, I swear <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </P><br />
<P>During the break at the UG, I started chatting with <A href="http://dotnetjunkies.com/WebLog/leon/">Leon Langleyben</A>&nbsp;(yes, it did take me 7 tries until I spelled that right) about TDD.</P><br />
<P>I stated that, as opposed to XP, TDD&#8217;s entry barrier would quite low and could still be quite effective. Leon countered by saying that getting the customer to sign-off on it might be problematic seeing as it increases up-front development time, or rather, decreases the rate at which the customer sees new functionality being developed.</P><br />
<P>I agree that this is true in cases where there is a high level of transparency into the development process. However, I believe that it would be easier to convince anybody to use TDD than it would be to convince them to use XP.</P><br />
<P>Specifically, one of the cases that Roy stated was problematic for XP was fixed-price projects. Now, I don&#8217;t entirely agree on this, however, in this case, nobody needs to know you&#8217;re using TDD, besides (maybe) your immediate manager, so it should be quite a bit easier to start easing in XP practices on at a time once TDD is in.</P><br />
<P>I&#8217;m still grokking this, but I think that TDD might just be oil that will allow XP to ease into an organization. Anybody whose had experience doing this, drop me a line and let me know. I think that it would be most valuable to me, and to a lot of people I know, so share the love <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </P></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/07/05/wrangling-over-tdd-with-leon/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>When I want your opinion, I&#8217;ll GIVE it to you !</title>
		<link>http://www.udidahan.com/2004/03/08/when-i-want-your-opinion-ill-give-it-to-you/</link>
		<comments>http://www.udidahan.com/2004/03/08/when-i-want-your-opinion-ill-give-it-to-you/#comments</comments>
		<pubDate>Tue, 09 Mar 2004 05:41:28 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/45</guid>
		<description><![CDATA[My <a href="http://udidahan.weblogs.us/archives/017367.html">recent post</a> sparked some contraversy on the extreme programming group and <a href="http://groups.yahoo.com/group/extremeprogramming/message/89931">the discussion</a> is worth while.
<BR><BR>
BTW - the title is a quote from my favorite teacher.]]></description>
			<content:encoded><![CDATA[<p><P>My <A href="http://udidahan.weblogs.us/2004/03/05/xp-covers-tdds-a/">recent post about XP and TDD</A>&nbsp;sparked some contraversy on the extreme programming group and <A href="http://groups.yahoo.com/group/extremeprogramming/message/89931">the discussion</A> is worth while. </P><br />
<P>BTW &#8211; the title is a quote from my favorite teacher.</P></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/03/08/when-i-want-your-opinion-ill-give-it-to-you/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>XP covers TDD&#8217;s a$$</title>
		<link>http://www.udidahan.com/2004/03/05/xp-covers-tdds-a/</link>
		<comments>http://www.udidahan.com/2004/03/05/xp-covers-tdds-a/#comments</comments>
		<pubDate>Sat, 06 Mar 2004 05:00:04 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/44</guid>
		<description><![CDATA[<p>
I think that I've already said this about a million times, but it bears repeating. Test driven development does not a well tested system make. OK, "So what good is TDD then ?", you ask.
</p><p>
First, let's prove my original claim. In order to test a simple method like "long add(int a, int b)" you have to write a ridiculous amount of tests. Checking for range and sign are just the start of it, because that will at best tell you that it's behaving ok. But what about performance ? Is it performant enough ? Does it behave in multi-threading situations ? What about when you're out of memory ? And on, and on.
</p><p>
In order to properly test anything, so that your as close to 100% sure as you can that any possible use of the code will work as expected, requires a lot of thought, time, and code.
</p><p>
If you're going to do all this on every bit of code you write, you'll never finish anything ! And, of course, there will be some tests you forget to write, so you can't really be sure that your tests will catch all the potential problems.
</p><p>
The TDD gurus will tell you that TDD is not about writing every possible test for every bit of code. BTW, studies have shown that testing is an inferior technique for reducing defects in code than code inspection. Of course, XP has pair-programming for constant code inspection for exactly this reason. 
</p><p>
So, if TDD doesn't give you a well tested system or particularly reduce defects, why the hell should you run around writing all these tests ?
</p><p>
There are 2 (main) reasons.
</p><p>
1. TDD is a "design" technique. It makes you think about how you'll use your code, before you write it. This leads to higher quality code. Coupled with YAGNI ( you aren't gonna need it ) from XP, and you prevent over-engineering.
</p><p>
2. TDD pushes the creation of many tests that show that the system is behaving as expected under given assumptions. This is important ! Document your assumptions. In code. In your tests. As assertions. Without the assumptions, you'll be bumping your way around a dark room forgetting everything after each bump.
</p><p>
But here's the point: The tests act as change detectors.
</p><p>
Whenever something changes ( usually one of the assumptions you made has now been found to be false as a result of some other code being written ), the place where your assumption appears, blows up.
</p><p>
Hooray !
</p><p>
There's nothing better than the code standing up and yelling "Hey, over here ! This here's broken ! Come fix it."
</p><p>
On the other hand, it could be that the assumption is still valid, and then the person that wrote the code will see that their use of it is wrong. Hopefully sooner rather than later. Continuous integration would let them know right away. ( Getting pretty obvious why in XP you see all the techniques together - by themselves, they have holes, together, each covers the other's holes. )
</p><p>
So, although TDD is a good technique, it doesn't give much in the way of actually testing the system. Enter XP, yet again. Integration testing, on-site customer that checks (tests) that a story is complete, all contribute to the "coverage". However, one of the places that XP does not have a technique built in, is when it comes to serious testing. Performance, scalability, out-of-resource situations are all areas which must be specifically tested for. They are not part of the rhythm which makes up XP.
</p><p>
This then defines a family of systems for which XP automatically does not quite fit. Systems which have stringent performance or scalability requirements will need to have the XP methodology tweaked so that they don't run into problems. 
</p><p>
One common workaround is this - create customer stories for performance. Its simple, easy, and doesn't break the rhythm. But woe to those who forget. That's the only reason why I bring it up, because XP doesn't take care of it for you like all the rest.
</p><p>
Final point: if you're doing TDD, but not XP, you're missing out. XP covers TDD's ass.
</p>]]></description>
			<content:encoded><![CDATA[<p><P>I think that I&#8217;ve already said this about a million times, but it bears repeating. Test driven development does not a well tested system make. OK, &#8220;So what good is TDD then ?&#8221;, you ask.</P><br />
<P>First, let&#8217;s prove my original claim. In order to test a simple method like &#8220;long add(int a, int b)&#8221; you have to write a ridiculous amount of tests. Checking for range and&nbsp;sign are just the start of it, because that will at best tell you that it&#8217;s behaving ok. But what about performance ? Is it performant enough ? Does it behave in multi-threading situations ? What about when you&#8217;re out of memory ? And on, and on.</P><br />
<P>In order to properly test anything, so that your as close to 100% sure as you can that any possible use of the code will work as expected, requires a lot of thought, time, and code.</P><br />
<P>If you&#8217;re going to do <EM>all</EM> this on <EM>every</EM> bit of code you write, you&#8217;ll never finish anything ! And, of course, there will be some tests you forget to write, so you can&#8217;t really be sure that your tests will catch all the potential problems.</P><br />
<P>The TDD gurus will tell you that TDD is not about writing every possible test for every bit of code. BTW, studies have shown that testing is an inferior technique for reducing defects in code than code inspection. Of course, XP has pair-programming for constant code inspection for exactly this reason. </P><br />
<P>So, if TDD doesn&#8217;t give you a well tested system or particularly reduce defects, why the hell should you run around writing all these tests ?</P><br />
<P>There are 2 (main) reasons.</P><br />
<P>1. TDD is a &#8220;design&#8221; technique. It makes you think about how you&#8217;ll use your code, before you write it. This leads to higher quality code. Coupled with YAGNI ( you aren&#8217;t gonna need it ) from XP, and you prevent over-engineering.</P><br />
<P>2. TDD pushes the creation of many tests that show that the system is behaving as expected under given assumptions. <STRONG>This is important !</STRONG> Document your assumptions. <STRONG>In code. </STRONG>In your tests. As assertions. Without the assumptions, you&#8217;ll be bumping your way around a dark room forgetting everything after each bump.</P><br />
<P>But here&#8217;s the point: The tests act as change detectors.</P><br />
<P>Whenever something changes ( usually one of the assumptions you made has now been found to be false as a result of some other code being written ), the place where your assumption appears, blows up.</P><br />
<P>Hooray !</P><br />
<P>There&#8217;s nothing better than the code standing up and yelling &#8220;Hey, over here ! This here&#8217;s broken ! Come fix it.&#8221;</P><br />
<P>On the other hand, it could be that the assumption is still valid, and then the person that wrote the code will see that their use of it is wrong. Hopefully sooner rather than later. Continuous integration would let them know right away. ( Getting pretty obvious why in XP you see all the techniques together &#8211; by themselves, they have holes, together, each covers the other&#8217;s holes. )</P><br />
<P>So, although TDD is a good technique, it doesn&#8217;t give much in the way of actually&nbsp;testing the system. Enter XP, yet again. Integration testing, on-site customer that checks (tests) that a story is complete, all contribute to the &#8220;coverage&#8221;. However, one of the places that XP does not have a technique built in, is when it comes to serious testing. Performance, scalability, out-of-resource situations are all areas which must be specifically tested for. They are not part of the rhythm which makes up XP.</P><br />
<P>This then defines a family of systems for which XP automatically does not quite fit. Systems which have stringent performance or scalability requirements will need to have the XP methodology tweaked so that they don&#8217;t run into problems. </P><br />
<P>One common workaround is this &#8211; create customer stories for performance. Its simple, easy, and doesn&#8217;t break the rhythm. But woe to those who forget. That&#8217;s the only reason why I bring it up, because XP doesn&#8217;t take care of it for you like all the rest.</P><br />
<P>Final point: if you&#8217;re doing TDD, but not XP, you&#8217;re missing out. XP covers TDD&#8217;s ass.</P></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/03/05/xp-covers-tdds-a/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
