<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Design and Testability &#8211; YAGNI</title>
	<atom:link href="http://www.elilopian.com/2007/03/04/design-and-testability-yagni/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/</link>
	<description>Creating better software</description>
	<lastBuildDate>Mon, 02 Jan 2012 09:09:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Eli Lopian</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-136</link>
		<dc:creator>Eli Lopian</dc:creator>
		<pubDate>Wed, 07 Mar 2007 07:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-136</guid>
		<description>I have been thinking hard if I should actually reply to the last post as it will be explaining a joke, and, well, explaining jokes is an useless as searching Google without an internet connection.

[If you didn&#039;t understand the context. The post is about a (well known) IoC implementation.]</description>
		<content:encoded><![CDATA[<p>I have been thinking hard if I should actually reply to the last post as it will be explaining a joke, and, well, explaining jokes is an useless as searching Google without an internet connection.</p>
<p>[If you didn't understand the context. The post is about a (well known) IoC implementation.]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yoni</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-135</link>
		<dc:creator>Yoni</dc:creator>
		<pubDate>Wed, 07 Mar 2007 06:41:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-135</guid>
		<description>It is a good one indeed. It has little to do with designing for testability though.

You see, using a container that loads different implementations at runtime based on a configuration file is just as awkward as hooking to constructors at runtime and returning a different implementation. The obvious way of doing things is simply having the tested code use an external object you can easily replace at runtime by simply sending in a mock that exposes the same interface.

But I guess I&#039;m just making myself more enemies now so maybe it&#039;s time to move on to a different subject.</description>
		<content:encoded><![CDATA[<p>It is a good one indeed. It has little to do with designing for testability though.</p>
<p>You see, using a container that loads different implementations at runtime based on a configuration file is just as awkward as hooking to constructors at runtime and returning a different implementation. The obvious way of doing things is simply having the tested code use an external object you can easily replace at runtime by simply sending in a mock that exposes the same interface.</p>
<p>But I guess I&#8217;m just making myself more enemies now so maybe it&#8217;s time to move on to a different subject.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eli Lopian</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-132</link>
		<dc:creator>Eli Lopian</dc:creator>
		<pubDate>Tue, 06 Mar 2007 21:14:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-132</guid>
		<description>Yonni, 
Anders found a really funny post on the subject: http://andersnoras.com/blogs/anoras/archive/2007/03/06/found-the-day-i-tried-to-learn-spring-and-hibernate.aspx</description>
		<content:encoded><![CDATA[<p>Yonni,<br />
Anders found a really funny post on the subject: <a href="http://andersnoras.com/blogs/anoras/archive/2007/03/06/found-the-day-i-tried-to-learn-spring-and-hibernate.aspx" rel="nofollow">http://andersnoras.com/blogs/anoras/archive/2007/03/06/found-the-day-i-tried-to-learn-spring-and-hibernate.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yoni</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-129</link>
		<dc:creator>Yoni</dc:creator>
		<pubDate>Tue, 06 Mar 2007 21:01:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-129</guid>
		<description>:-) Nice.

Well, my bad, I thought we were discussing OOP. AOP is not exactly my cup of tea as you can tell. But that&#039;s a whole new discussion...

Using AOP and wiring class initializers instead of simple polymorphism, seems to me like a You Ain&#039;t Gonna Need It :-)</description>
		<content:encoded><![CDATA[<p> <img src='http://www.elilopian.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Nice.</p>
<p>Well, my bad, I thought we were discussing OOP. AOP is not exactly my cup of tea as you can tell. But that&#8217;s a whole new discussion&#8230;</p>
<p>Using AOP and wiring class initializers instead of simple polymorphism, seems to me like a You Ain&#8217;t Gonna Need It <img src='http://www.elilopian.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eli Lopian</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-127</link>
		<dc:creator>Eli Lopian</dc:creator>
		<pubDate>Tue, 06 Mar 2007 18:58:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-127</guid>
		<description>Yoni,
Welcome to Aspect Oriented Programming/Aspect Oriented Software Design.
This is exactly what an AOD Framework can do and more. And yes it is used in production code :-)

Adding a testability aspect without changing your code is only one of many aspects you can add.
Others can be:
    * security
    * performance
    * optimization
    * accuracy
    * data representation
    * data flow
    * portability
    * traceability
    * profiling 
(See http://www.codeproject.com/gen/design/aop.asp)

And with the right tools, this can and will be easy.</description>
		<content:encoded><![CDATA[<p>Yoni,<br />
Welcome to Aspect Oriented Programming/Aspect Oriented Software Design.<br />
This is exactly what an AOD Framework can do and more. And yes it is used in production code <img src='http://www.elilopian.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Adding a testability aspect without changing your code is only one of many aspects you can add.<br />
Others can be:<br />
    * security<br />
    * performance<br />
    * optimization<br />
    * accuracy<br />
    * data representation<br />
    * data flow<br />
    * portability<br />
    * traceability<br />
    * profiling<br />
(See <a href="http://www.codeproject.com/gen/design/aop.asp)" rel="nofollow">http://www.codeproject.com/gen/design/aop.asp)</a></p>
<p>And with the right tools, this can and will be easy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yoni</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-126</link>
		<dc:creator>Yoni</dc:creator>
		<pubDate>Tue, 06 Mar 2007 18:31:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-126</guid>
		<description>&quot;But today: You don’t need to change your code to make it testable, so the whole issue is resolved.&quot;

In that case, I also don&#039;t need to refactor in order to support writing to an SMS. All I have to do is run my application on a TypeMock-like framework and have the File class be substituted at runtime to a different implementation (one that sends SMS&#039;s) before calling DoSomething().

Would you like maintaining code that hooks on class instantiators and replaces them at runtime instead of using plain old polymorphism? 
But that it exactly what TypeMock does so you are saying that a technique no-one would want to use in production code is good for test code - why?

You are right, of course, about my DoSomething() that accepts IFile. But if you have a test that asserts that the File class is being used inside DoSomething() you have the same problem with encapsulation because once a different class is used to perform the same behaviour your test will have to be rewritten.</description>
		<content:encoded><![CDATA[<p>&#8220;But today: You don’t need to change your code to make it testable, so the whole issue is resolved.&#8221;</p>
<p>In that case, I also don&#8217;t need to refactor in order to support writing to an SMS. All I have to do is run my application on a TypeMock-like framework and have the File class be substituted at runtime to a different implementation (one that sends SMS&#8217;s) before calling DoSomething().</p>
<p>Would you like maintaining code that hooks on class instantiators and replaces them at runtime instead of using plain old polymorphism?<br />
But that it exactly what TypeMock does so you are saying that a technique no-one would want to use in production code is good for test code &#8211; why?</p>
<p>You are right, of course, about my DoSomething() that accepts IFile. But if you have a test that asserts that the File class is being used inside DoSomething() you have the same problem with encapsulation because once a different class is used to perform the same behaviour your test will have to be rewritten.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eli Lopian</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-125</link>
		<dc:creator>Eli Lopian</dc:creator>
		<pubDate>Tue, 06 Mar 2007 17:53:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-125</guid>
		<description>Yoni,
Thanks for your thoughts, they are interesting and you have a point here.

I have had this discussion over 4 years ago.
At that time it was a hot debate on the net.
OO and XP purist where debating whether refactoring code for testability was violating YAGNI.
The purist where saying:
&quot;refactoring your code just to make it testable does NOT violate YAGNI because you need it &quot;right now&quot; for testing&quot;

I will add: And Testing has business value.

But today: You don&#039;t need to change your code to make it testable, so the whole issue is resolved.

About your code example: The way YAGNI works is that you start with the first example. 
If and only if there is a new feature that we have to add, we refactor our code (extract and introduce a new method and implement the new feature - Some IDE&#039;s will even find similar lines and do all the hard stuff for you). 

So if in some time in the future you have to send all the messages to an SMS for example, then you can refactor your code. And by the way, in most cases you won&#039;t have to change your tests, because you will leave the older implementation.

Also notice that in the second example, now all code that calls DoSomething() must know IFile. So you are actually lowering the cohesion (by having a less encapsulated system) in order to have a lower coupled system. This is a Design Decision that &#039;Testabilty&#039; automatically makes for you.</description>
		<content:encoded><![CDATA[<p>Yoni,<br />
Thanks for your thoughts, they are interesting and you have a point here.</p>
<p>I have had this discussion over 4 years ago.<br />
At that time it was a hot debate on the net.<br />
OO and XP purist where debating whether refactoring code for testability was violating YAGNI.<br />
The purist where saying:<br />
&#8220;refactoring your code just to make it testable does NOT violate YAGNI because you need it &#8220;right now&#8221; for testing&#8221;</p>
<p>I will add: And Testing has business value.</p>
<p>But today: You don&#8217;t need to change your code to make it testable, so the whole issue is resolved.</p>
<p>About your code example: The way YAGNI works is that you start with the first example.<br />
If and only if there is a new feature that we have to add, we refactor our code (extract and introduce a new method and implement the new feature &#8211; Some IDE&#8217;s will even find similar lines and do all the hard stuff for you). </p>
<p>So if in some time in the future you have to send all the messages to an SMS for example, then you can refactor your code. And by the way, in most cases you won&#8217;t have to change your tests, because you will leave the older implementation.</p>
<p>Also notice that in the second example, now all code that calls DoSomething() must know IFile. So you are actually lowering the cohesion (by having a less encapsulated system) in order to have a lower coupled system. This is a Design Decision that &#8216;Testabilty&#8217; automatically makes for you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yoni</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-124</link>
		<dc:creator>Yoni</dc:creator>
		<pubDate>Tue, 06 Mar 2007 16:36:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-124</guid>
		<description>I thought a lot about your YAGNI argument against using polymorphism to insert mock objects in tests. I think you are forgetting that unit tests are a part of the system&#039;s code and that their readability and maintainability is just as important as that of the rest of the system. This is why inserting access points in my design for tests is not a YAGNI - I need it for the tests.
Your argument is that I don&#039;t have to use polimorphism because TypeMock can replace concrete calls at runtime - but that is true not only for unit tests. Using reflection I can replace concrete calls at runtime wherever I wish but this is obviously a poor design decision. So why are tests any different?

Now let me ask you what is easier to maintain, this:

public void DoSomething()
{
File.WriteAllText(filename, text);
}

[Test]
public void TestWithTypeMock()
{
MockManager.Init();
Mock myMock = MockManager.Mock(typeof(File));
myMock.ExpectCall(&quot;WriteAllText&quot;);
DoSomething();
myMock.Verify();
}

or this:

public void DoSomething(IFile file)
{
file.WriteAllText(filename,text);
}

class MockFile : IFile
{
public bool _writeAllTextCalled = false;
public void WriteAllText(string filename, string text)
{
_writeAllTextCalled = true;
}
}

[Test]
public void TestUsingStandartMock()
{
MockFile file = new MockFile();
DoSomething(file);
NUnit.Framework.Assert.IsTrue(file._writeAllTextCalled);
}

Which one of these implementations would better survive a change in the name &quot;WriteAllText&quot;?</description>
		<content:encoded><![CDATA[<p>I thought a lot about your YAGNI argument against using polymorphism to insert mock objects in tests. I think you are forgetting that unit tests are a part of the system&#8217;s code and that their readability and maintainability is just as important as that of the rest of the system. This is why inserting access points in my design for tests is not a YAGNI &#8211; I need it for the tests.<br />
Your argument is that I don&#8217;t have to use polimorphism because TypeMock can replace concrete calls at runtime &#8211; but that is true not only for unit tests. Using reflection I can replace concrete calls at runtime wherever I wish but this is obviously a poor design decision. So why are tests any different?</p>
<p>Now let me ask you what is easier to maintain, this:</p>
<p>public void DoSomething()<br />
{<br />
File.WriteAllText(filename, text);<br />
}</p>
<p>[Test]<br />
public void TestWithTypeMock()<br />
{<br />
MockManager.Init();<br />
Mock myMock = MockManager.Mock(typeof(File));<br />
myMock.ExpectCall(&#8220;WriteAllText&#8221;);<br />
DoSomething();<br />
myMock.Verify();<br />
}</p>
<p>or this:</p>
<p>public void DoSomething(IFile file)<br />
{<br />
file.WriteAllText(filename,text);<br />
}</p>
<p>class MockFile : IFile<br />
{<br />
public bool _writeAllTextCalled = false;<br />
public void WriteAllText(string filename, string text)<br />
{<br />
_writeAllTextCalled = true;<br />
}<br />
}</p>
<p>[Test]<br />
public void TestUsingStandartMock()<br />
{<br />
MockFile file = new MockFile();<br />
DoSomething(file);<br />
NUnit.Framework.Assert.IsTrue(file._writeAllTextCalled);<br />
}</p>
<p>Which one of these implementations would better survive a change in the name &#8220;WriteAllText&#8221;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yoni</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-120</link>
		<dc:creator>Yoni</dc:creator>
		<pubDate>Tue, 06 Mar 2007 09:01:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-120</guid>
		<description>How about:

public void DoSomething(IFileSystem fileSystem)
{
fileSystem.WriteAllText(filename, text);
}</description>
		<content:encoded><![CDATA[<p>How about:</p>
<p>public void DoSomething(IFileSystem fileSystem)<br />
{<br />
fileSystem.WriteAllText(filename, text);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anders Norås</title>
		<link>http://www.elilopian.com/2007/03/04/design-and-testability-yagni/comment-page-1/#comment-114</link>
		<dc:creator>Anders Norås</dc:creator>
		<pubDate>Mon, 05 Mar 2007 18:03:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/03/04/design-and-testability-yagni/#comment-114</guid>
		<description>&lt;a href=&quot;http://andersnoras.com/blogs/anoras/archive/2007/03/04/balancing-maintainability-readability-and-testability.aspx&quot; rel=&quot;nofollow&quot;&gt;Balancing Maintainability, Readability and Testability&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p><a href="http://andersnoras.com/blogs/anoras/archive/2007/03/04/balancing-maintainability-readability-and-testability.aspx" rel="nofollow">Balancing Maintainability, Readability and Testability</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

