<?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: Making Code More Testable &#8211; Breaking Static Dependencies</title>
	<atom:link href="http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/feed/" rel="self" type="application/rss+xml" />
	<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/</link>
	<description>Nobody can be perfect, but you can think better, design better, and always use baby steps!</description>
	<lastBuildDate>Tue, 22 Nov 2011 10:53:40 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Making Code More Testable – Breaking Static Dependencies &#124; Software Testing &#38; Quality Assurance Videos Directory</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3601</link>
		<dc:creator>Making Code More Testable – Breaking Static Dependencies &#124; Software Testing &#38; Quality Assurance Videos Directory</dc:creator>
		<pubDate>Tue, 29 Sep 2009 12:21:25 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3601</guid>
		<description>&lt;p&gt;[...] Watch this screencast on isagoksu.com [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] Watch this screencast on isagoksu.com [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Making Code More Testable – Breaking Static Dependencies &#124; Software Development Videos</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3600</link>
		<dc:creator>Making Code More Testable – Breaking Static Dependencies &#124; Software Development Videos</dc:creator>
		<pubDate>Tue, 29 Sep 2009 12:21:07 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3600</guid>
		<description>&lt;p&gt;[...] Watch this screencast on isagoksu.com [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] Watch this screencast on isagoksu.com [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Isa Goksu</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3317</link>
		<dc:creator>Isa Goksu</dc:creator>
		<pubDate>Mon, 07 Sep 2009 01:02:28 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3317</guid>
		<description>&lt;p&gt;@gavin 10x for the comment. Yeah that could have been done for the second part of the implementation. Then again it&#039;s just a personal choice. I&#039;m not in favour or writing tests first for delegator methods. As I said, personal choice. To me &#039;Agile&#039; and &#039;TDD&#039; have so vague concepts and everybody has an opinion about them. Some says &#039;this has to be done this way&#039;, some says &#039;no actually the other way&#039;. And if you look at the titles of those people you would be surprised why their comments don&#039;t match:D Anyways, I believe in TED (Test Enhanced Development) rather than TFD (Test First Design). To me it sounds more logical. And think about it as long as you keep your units tested, we can&#039;t say it&#039;s a bad propagation right? Johannes Link and Peter Fröhlich has a nice chapter in &#039;Unit Testing in Java&#039; (somewhere in the middle of the book) that covers these sort of topics. For those who can&#039;t decide how much is enough, they can refer to that book.&lt;/p&gt;

&lt;p&gt;And Misko is one of the heroes of this topic. I think there is not much of a guy like him that still insists on testable codes rather than unit testing :)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@gavin 10x for the comment. Yeah that could have been done for the second part of the implementation. Then again it&#8217;s just a personal choice. I&#8217;m not in favour or writing tests first for delegator methods. As I said, personal choice. To me &#8216;Agile&#8217; and &#8216;TDD&#8217; have so vague concepts and everybody has an opinion about them. Some says &#8216;this has to be done this way&#8217;, some says &#8216;no actually the other way&#8217;. And if you look at the titles of those people you would be surprised why their comments don&#8217;t match:D Anyways, I believe in TED (Test Enhanced Development) rather than TFD (Test First Design). To me it sounds more logical. And think about it as long as you keep your units tested, we can&#8217;t say it&#8217;s a bad propagation right? Johannes Link and Peter Fröhlich has a nice chapter in &#8216;Unit Testing in Java&#8217; (somewhere in the middle of the book) that covers these sort of topics. For those who can&#8217;t decide how much is enough, they can refer to that book.</p>

<p>And Misko is one of the heroes of this topic. I think there is not much of a guy like him that still insists on testable codes rather than unit testing :)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Gavin Clarke</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3313</link>
		<dc:creator>Gavin Clarke</dc:creator>
		<pubDate>Sun, 06 Sep 2009 11:47:03 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3313</guid>
		<description>&lt;p&gt;Nice demo, but please write your tests first!  Lets not propogate bad habits.&lt;/p&gt;

&lt;p&gt;Also for the other commenters, if you want more info on writing testable code, and why DI really helps then check out Misko Hevery&#039;s Clean Code talks - http://misko.hevery.com/2008/11/04/clean-code-talks-unit-testing/&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Nice demo, but please write your tests first!  Lets not propogate bad habits.</p>

<p>Also for the other commenters, if you want more info on writing testable code, and why DI really helps then check out Misko Hevery&#8217;s Clean Code talks &#8211; <a href="http://misko.hevery.com/2008/11/04/clean-code-talks-unit-testing/" rel="nofollow">http://misko.hevery.com/2008/11/04/clean-code-talks-unit-testing/</a></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rogério Liesenfeld</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3268</link>
		<dc:creator>Rogério Liesenfeld</dc:creator>
		<pubDate>Tue, 01 Sep 2009 00:56:08 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3268</guid>
		<description>&lt;p&gt;I really try to keep an open mind about DI, but I always seem to get frustated with what I find. If you read the Guice or Spring IOC documentation, for example, there is hardly any logical argumentation or examples about the value of DI, apart from the outdated talk about unit testing (which really only reflects the limitations of certain other mocking tools).&lt;/p&gt;

&lt;p&gt;I would like to find a good text that explains how DI helps make code more modular or maintainable. What I have seen so far leads me to believe that DI often is detrimental to OO design.&lt;/p&gt;

&lt;p&gt;Specifically, developers tend to make service classes stateless instead of stateful, so they can be singletons. This is not good design. I prefer to favor stateful service classes, with instance lifetimes limited to the business operations that rely on them. Such instances are typically created with context-specific data, usually coming from the UI. Using DI would prevent me from doing this. Also, DI requires dependencies that would otherwise be private to be publicy exposed; this violates the information hiding principle.
And lets not forget about the KISS and YAGNI principles.&lt;/p&gt;

&lt;p&gt;A good example of DI abuse is the DDD sample application. It can be simplified a lot, without any obvious loss in design qualities. I actually intend to create a JMockit-based version of it when I get the time, as another sample for the toolkit.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I really try to keep an open mind about DI, but I always seem to get frustated with what I find. If you read the Guice or Spring IOC documentation, for example, there is hardly any logical argumentation or examples about the value of DI, apart from the outdated talk about unit testing (which really only reflects the limitations of certain other mocking tools).</p>

<p>I would like to find a good text that explains how DI helps make code more modular or maintainable. What I have seen so far leads me to believe that DI often is detrimental to OO design.</p>

<p>Specifically, developers tend to make service classes stateless instead of stateful, so they can be singletons. This is not good design. I prefer to favor stateful service classes, with instance lifetimes limited to the business operations that rely on them. Such instances are typically created with context-specific data, usually coming from the UI. Using DI would prevent me from doing this. Also, DI requires dependencies that would otherwise be private to be publicy exposed; this violates the information hiding principle.
And lets not forget about the KISS and YAGNI principles.</p>

<p>A good example of DI abuse is the DDD sample application. It can be simplified a lot, without any obvious loss in design qualities. I actually intend to create a JMockit-based version of it when I get the time, as another sample for the toolkit.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Isa Goksu</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3267</link>
		<dc:creator>Isa Goksu</dc:creator>
		<pubDate>Mon, 31 Aug 2009 23:36:53 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3267</guid>
		<description>&lt;p&gt;I think I should fix that sentence. Apparently it&#039;s misleading:)&lt;/p&gt;

&lt;p&gt;About your concerns with DI vs in-method dependencies, both side has its own advantages and disadvantages. We can&#039;t put a silver bullet rule for all conditions. My experience with DI tells me good things rather than its complexity. However I agree that if you&#039;re using Spring sort of frameworks you might end up having lots of interfaces or setter methods which you&#039;ll never need. I already mentioned this problem in one of my previous article (@see Naming Java Implementation Classes). Then again to me creating a nice dependency mechanism makes code much more readable and easy to understand. The quantity of your java classes or methods doesn&#039;t matter, I think having clean code is very important. And without DI or principles/patterns, people feel themselves so free and goes into procedural programming rather than OOP. And following these sort of principles/patterns keeps the conventions. When you see a code that uses these conventions, it&#039;s really not hard to adapt it. But as I said, both usages have their own benefits. I can&#039;t argue about it although I feel myself more comfortable in the DI side.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I think I should fix that sentence. Apparently it&#8217;s misleading:)</p>

<p>About your concerns with DI vs in-method dependencies, both side has its own advantages and disadvantages. We can&#8217;t put a silver bullet rule for all conditions. My experience with DI tells me good things rather than its complexity. However I agree that if you&#8217;re using Spring sort of frameworks you might end up having lots of interfaces or setter methods which you&#8217;ll never need. I already mentioned this problem in one of my previous article (@see Naming Java Implementation Classes). Then again to me creating a nice dependency mechanism makes code much more readable and easy to understand. The quantity of your java classes or methods doesn&#8217;t matter, I think having clean code is very important. And without DI or principles/patterns, people feel themselves so free and goes into procedural programming rather than OOP. And following these sort of principles/patterns keeps the conventions. When you see a code that uses these conventions, it&#8217;s really not hard to adapt it. But as I said, both usages have their own benefits. I can&#8217;t argue about it although I feel myself more comfortable in the DI side.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rogério Liesenfeld</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3266</link>
		<dc:creator>Rogério Liesenfeld</dc:creator>
		<pubDate>Mon, 31 Aug 2009 22:32:51 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3266</guid>
		<description>&lt;p&gt;Well, you specifically wrote &quot;there is no way for us to test this unit&quot;, concerning &quot;MyClass&quot;. So it seems to me that it is indeed about the possibility or impossibility of unit testing the code.&lt;/p&gt;

&lt;p&gt;How easy it is to unit test a piece should only depend on its intrinsic complexity, not on accidental characteristics.
For example, it should not matter if the code makes use of constructors, final classes/methods, static methods, or whatever. These are all perfectly valid Java language features and idioms.&lt;/p&gt;

&lt;p&gt;The problem with using DI (or any other principle or pattern) for the sake of unit testing is that it will tend to make the code more complex, often with pointless  interfaces/abstractions, &quot;setter methods&quot;, &quot;wiring configuration&quot;, etc. that only add noise to the codebase.&lt;/p&gt;

&lt;p&gt;Clean, short and elegant unit tests can be written for any production code, depending only on the essential complexity of the tested code. DI really only adds complexity, not reduces it.&lt;/p&gt;

&lt;p&gt;Doing this in real-world projects has nothing to do with how knowledgeable a developer is. The developers will need to learn the mocking API, that&#039;s all. Compare that to learning Guice or Spring IOC.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Well, you specifically wrote &#8220;there is no way for us to test this unit&#8221;, concerning &#8220;MyClass&#8221;. So it seems to me that it is indeed about the possibility or impossibility of unit testing the code.</p>

<p>How easy it is to unit test a piece should only depend on its intrinsic complexity, not on accidental characteristics.
For example, it should not matter if the code makes use of constructors, final classes/methods, static methods, or whatever. These are all perfectly valid Java language features and idioms.</p>

<p>The problem with using DI (or any other principle or pattern) for the sake of unit testing is that it will tend to make the code more complex, often with pointless  interfaces/abstractions, &#8220;setter methods&#8221;, &#8220;wiring configuration&#8221;, etc. that only add noise to the codebase.</p>

<p>Clean, short and elegant unit tests can be written for any production code, depending only on the essential complexity of the tested code. DI really only adds complexity, not reduces it.</p>

<p>Doing this in real-world projects has nothing to do with how knowledgeable a developer is. The developers will need to learn the mocking API, that&#8217;s all. Compare that to learning Guice or Spring IOC.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Isa Goksu</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3264</link>
		<dc:creator>Isa Goksu</dc:creator>
		<pubDate>Mon, 31 Aug 2009 21:28:15 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3264</guid>
		<description>&lt;p&gt;@eugen 10x,&lt;/p&gt;

&lt;p&gt;@rogerio, problem is not about can/cannot test the code. It&#039;s &#039;&lt;u&gt;how easy&lt;/u&gt;&#039; to test the code. The assumption is generally declared like that to actually describe this situation. Just think like this, if your constructor or any of your method does amazing job in its implementation by keeping all in-method dependencies, maybe a developer could do some testing using his/her advanced knowledge. However do you think is this really required to do a simple unit testing? Or is there a major need to make your code this much complicated? To me there are couple issues here. First it makes harder for the next developer to adapt the code! Second it&#039;s very hard to maintain &#039;coz lots of things have in-method dependencies. And third it increases the risk  of potential problems. And last but not least is code like this is hard to read/understand. I see your point, but you can&#039;t expect every developer in your team to be as knowledgeable as you&#039;re. Hope we&#039;re on the same page here..&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@eugen 10x,</p>

<p>@rogerio, problem is not about can/cannot test the code. It&#8217;s &#8216;<u>how easy</u>&#8216; to test the code. The assumption is generally declared like that to actually describe this situation. Just think like this, if your constructor or any of your method does amazing job in its implementation by keeping all in-method dependencies, maybe a developer could do some testing using his/her advanced knowledge. However do you think is this really required to do a simple unit testing? Or is there a major need to make your code this much complicated? To me there are couple issues here. First it makes harder for the next developer to adapt the code! Second it&#8217;s very hard to maintain &#8216;coz lots of things have in-method dependencies. And third it increases the risk  of potential problems. And last but not least is code like this is hard to read/understand. I see your point, but you can&#8217;t expect every developer in your team to be as knowledgeable as you&#8217;re. Hope we&#8217;re on the same page here..</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rogério Liesenfeld</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3263</link>
		<dc:creator>Rogério Liesenfeld</dc:creator>
		<pubDate>Mon, 31 Aug 2009 19:41:48 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3263</guid>
		<description>&lt;p&gt;Notice that this article relies on a critical assumption: that there are Java code constructs which are &quot;not testable&quot; (meaning that their use would prevent the isolation of a unit from its dependencies, in the context of a unit test).&lt;/p&gt;

&lt;p&gt;It turns out this assumption is false. The JVM really has some amazing abilities, which have been exposed in easy to use mocking APIs by certain open source tools.&lt;/p&gt;

&lt;p&gt;Today it&#039;s safe to say that, in the context of unit testing Java code, there is no such thing as &quot;untestable code&quot;.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Notice that this article relies on a critical assumption: that there are Java code constructs which are &#8220;not testable&#8221; (meaning that their use would prevent the isolation of a unit from its dependencies, in the context of a unit test).</p>

<p>It turns out this assumption is false. The JVM really has some amazing abilities, which have been exposed in easy to use mocking APIs by certain open source tools.</p>

<p>Today it&#8217;s safe to say that, in the context of unit testing Java code, there is no such thing as &#8220;untestable code&#8221;.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Eugen</title>
		<link>http://isagoksu.com/2009/development/agile-development/test-driven-development/making-code-more-testable-breaking-static-dependencies/comment-page-1/#comment-3262</link>
		<dc:creator>Eugen</dc:creator>
		<pubDate>Mon, 31 Aug 2009 19:34:08 +0000</pubDate>
		<guid isPermaLink="false">http://isagoksu.com/?p=531#comment-3262</guid>
		<description>&lt;p&gt;Very cool screencast, learned a lot. Keep up the good work.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Very cool screencast, learned a lot. Keep up the good work.</p>]]></content:encoded>
	</item>
</channel>
</rss>

