<?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"
	>
<channel>
	<title>Comments on: An easy way to make your code more testable</title>
	<atom:link href="http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/feed/" rel="self" type="application/rss+xml" />
	<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/</link>
	<description>Rambling about programming and life as a programmer - by Mathieu Martin</description>
	<pubDate>Fri, 21 Nov 2008 08:15:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Nick</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-110</link>
		<dc:creator>Nick</dc:creator>
		<pubDate>Tue, 18 Dec 2007 20:08:17 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-110</guid>
		<description>Quite right. Command-Query separation is needed.

My personal pet hate is functions like this

x = rand()

Its both a command and a query, and difficult to unit test.

In reality, it should be an iterator

x = random.value()
random.move_next()

Then you can test it.

The other advantage of command query is you can write code in this way.

if x.invalid():
    do_something()
else:
   x.calculate()

instead of

try:
   x.calculate()
except:
   do_something()

I personally don't like exceptions being use for flow control, unless you really, really need to. e.g. Inverting a matrix where the query on the matrix, is_inveritable() is very computationaly expensive.

Microsoft are awful at not having Command-Query separation.

Next stop, a decent design by contract implementation in dot net.

Nick</description>
		<content:encoded><![CDATA[<p>Quite right. Command-Query separation is needed.</p>
<p>My personal pet hate is functions like this</p>
<p>x = rand()</p>
<p>Its both a command and a query, and difficult to unit test.</p>
<p>In reality, it should be an iterator</p>
<p>x = random.value()<br />
random.move_next()</p>
<p>Then you can test it.</p>
<p>The other advantage of command query is you can write code in this way.</p>
<p>if x.invalid():<br />
    do_something()<br />
else:<br />
   x.calculate()</p>
<p>instead of</p>
<p>try:<br />
   x.calculate()<br />
except:<br />
   do_something()</p>
<p>I personally don&#8217;t like exceptions being use for flow control, unless you really, really need to. e.g. Inverting a matrix where the query on the matrix, is_inveritable() is very computationaly expensive.</p>
<p>Microsoft are awful at not having Command-Query separation.</p>
<p>Next stop, a decent design by contract implementation in dot net.</p>
<p>Nick</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Blog do Márcio d&#8217;Ávila</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-109</link>
		<dc:creator>Blog do Márcio d&#8217;Ávila</dc:creator>
		<pubDate>Mon, 17 Dec 2007 02:18:25 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-109</guid>
		<description>[...] recente artigo An easy way to make your code more testable, no blog Programblings, me levou a outro artigo [...]</description>
		<content:encoded><![CDATA[<p>[...] recente artigo An easy way to make your code more testable, no blog Programblings, me levou a outro artigo [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Whelan</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-107</link>
		<dc:creator>Rob Whelan</dc:creator>
		<pubDate>Sat, 15 Dec 2007 23:22:11 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-107</guid>
		<description>About coupling, testing in OOP, etc.
@Andreas -- the stack example is a good one.  You shouldn't try to somehow implement it as static methods (bad OOP.. it naturally has state), but if you cleanly separate your stack functionality from your *other* code, that's both good OOP and easily testable.

The side-effects of the Stack methods are simple and restricted to the instance, and hence straightforward to test.

The bad OOP approach (and the test-killing approach) is to just put a List in your business logic class, and *treat* it like a stack -- pushing items into one end, pulling them back out and deleting them....  Moving *that* code into a clean stack object puts a bunch of code into the realm of easy test coverage.

[Of course, it's even better just use the stack impl likely built into your language of choice.. but hey, we're talking concepts here.]</description>
		<content:encoded><![CDATA[<p>About coupling, testing in OOP, etc.<br />
@Andreas &#8212; the stack example is a good one.  You shouldn&#8217;t try to somehow implement it as static methods (bad OOP.. it naturally has state), but if you cleanly separate your stack functionality from your *other* code, that&#8217;s both good OOP and easily testable.</p>
<p>The side-effects of the Stack methods are simple and restricted to the instance, and hence straightforward to test.</p>
<p>The bad OOP approach (and the test-killing approach) is to just put a List in your business logic class, and *treat* it like a stack &#8212; pushing items into one end, pulling them back out and deleting them&#8230;.  Moving *that* code into a clean stack object puts a bunch of code into the realm of easy test coverage.</p>
<p>[Of course, it's even better just use the stack impl likely built into your language of choice.. but hey, we're talking concepts here.]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kabarety</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-108</link>
		<dc:creator>Kabarety</dc:creator>
		<pubDate>Sat, 15 Dec 2007 07:05:16 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-108</guid>
		<description>"So let’s say we start with the following method to analyze our arguments (to see the readable, indented version of this code, click here) :"

Thanks, great article... ;]</description>
		<content:encoded><![CDATA[<p>&#8220;So let’s say we start with the following method to analyze our arguments (to see the readable, indented version of this code, click here) :&#8221;</p>
<p>Thanks, great article&#8230; ;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stu</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-103</link>
		<dc:creator>Stu</dc:creator>
		<pubDate>Sat, 15 Dec 2007 04:39:23 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-103</guid>
		<description>Sam and Patrick are correct... in OOP, an object is data + behavior, which means that methods answer state and/or modify state. In a way, good OOP is all about side effects.  Thinking about coupling and cohesion is a GOOD thing.

I would assert that, contrary to the static method example given as a "good idea", static methods and instances are a BAD idea in OOP, especially when it comes to testing.  Static methods cannot (easily) be substituted by the test code to force certain code paths to be tested, and static variables are difficult to properly test.

Testing in an OOP language should be easy - create the object, set it to a known state, invoke the method, and inspect the new state.  Problems with testing tend to arise in a couple of areas: (1) creating the object is a laborious and tedious task, generally because the object is complicated and/or poorly designed; (2) the object exhibits poor cohesion and widespread coupling; and (3) the object's state is difficult or impossible to determine or interrogate.

(1) is an effect of leaving testing to a later part of the development cycle; testing early in the development cycle encourages the developer to make their life easy when it comes to creating an object with a known state.  Sometimes what is required is a builder-pattern, where a complicated configuration string (structured-key-value-pairs or XML or S-expressions or P-lists) can be provided to a helper class that spits out the appropriate object.

(2) is quite simply a design problem, often due to (in my experience) insufficient foresight or excessive fondness for the code. (Sometimes, you just have to throw the first one away.  If the cookies give you indigestion, frosting won't help.) Foresight is wonderful, but not dependable; it can warn you away from problematic paths, but it can't guide you towards the minimum-effort-maximum-success path in the general case.

(3) is a natural consequence of (2), but it also a natural consequence of hurried development, sloppy development, poor or inexperienced developers, and (what I call) demo-driven implementation. When you're trying to get some code out the door yesterday, it's natural to not think about testing, documentation, cohesion, coupling, appropriateness or lack of same of the "static" keyword, etc.   It's natural. But it also causes problems down the line.  The way to deal with this is to have a strong aesthetic (if you puzzle out what a method does, do you write a summary comment for that method? If not, why not -- should the next programmer have to duplicate all of your effort? Why?) and to, naturally, never forgo testing.

I just wish I were better at paying attention to my own advice.</description>
		<content:encoded><![CDATA[<p>Sam and Patrick are correct&#8230; in OOP, an object is data + behavior, which means that methods answer state and/or modify state. In a way, good OOP is all about side effects.  Thinking about coupling and cohesion is a GOOD thing.</p>
<p>I would assert that, contrary to the static method example given as a &#8220;good idea&#8221;, static methods and instances are a BAD idea in OOP, especially when it comes to testing.  Static methods cannot (easily) be substituted by the test code to force certain code paths to be tested, and static variables are difficult to properly test.</p>
<p>Testing in an OOP language should be easy - create the object, set it to a known state, invoke the method, and inspect the new state.  Problems with testing tend to arise in a couple of areas: (1) creating the object is a laborious and tedious task, generally because the object is complicated and/or poorly designed; (2) the object exhibits poor cohesion and widespread coupling; and (3) the object&#8217;s state is difficult or impossible to determine or interrogate.</p>
<p>(1) is an effect of leaving testing to a later part of the development cycle; testing early in the development cycle encourages the developer to make their life easy when it comes to creating an object with a known state.  Sometimes what is required is a builder-pattern, where a complicated configuration string (structured-key-value-pairs or XML or S-expressions or P-lists) can be provided to a helper class that spits out the appropriate object.</p>
<p>(2) is quite simply a design problem, often due to (in my experience) insufficient foresight or excessive fondness for the code. (Sometimes, you just have to throw the first one away.  If the cookies give you indigestion, frosting won&#8217;t help.) Foresight is wonderful, but not dependable; it can warn you away from problematic paths, but it can&#8217;t guide you towards the minimum-effort-maximum-success path in the general case.</p>
<p>(3) is a natural consequence of (2), but it also a natural consequence of hurried development, sloppy development, poor or inexperienced developers, and (what I call) demo-driven implementation. When you&#8217;re trying to get some code out the door yesterday, it&#8217;s natural to not think about testing, documentation, cohesion, coupling, appropriateness or lack of same of the &#8220;static&#8221; keyword, etc.   It&#8217;s natural. But it also causes problems down the line.  The way to deal with this is to have a strong aesthetic (if you puzzle out what a method does, do you write a summary comment for that method? If not, why not &#8212; should the next programmer have to duplicate all of your effort? Why?) and to, naturally, never forgo testing.</p>
<p>I just wish I were better at paying attention to my own advice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Top Posts &#171; WordPress.com</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-106</link>
		<dc:creator>Top Posts &#171; WordPress.com</dc:creator>
		<pubDate>Fri, 14 Dec 2007 23:58:46 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-106</guid>
		<description>[...]  An easy way to make your code more testable James Golick wrote a very good article about testing a while ago. In it he dissects (and refutes) the too often heard [&#8230;] [...]</description>
		<content:encoded><![CDATA[<p>[...]  An easy way to make your code more testable James Golick wrote a very good article about testing a while ago. In it he dissects (and refutes) the too often heard [&#8230;] [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thomas lackner</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-105</link>
		<dc:creator>thomas lackner</dc:creator>
		<pubDate>Fri, 14 Dec 2007 23:23:41 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-105</guid>
		<description>@Andreas,

A stack seems fairly easy to test; perform operation, check element on top and bottom of stack, and count of items in stack. That would reasonably assure that your stack is working correctly. Am I missing something?

Overall I agree that creating a side-effect-free non-trivial object is harder than isolated functions or FP-oriented code.</description>
		<content:encoded><![CDATA[<p>@Andreas,</p>
<p>A stack seems fairly easy to test; perform operation, check element on top and bottom of stack, and count of items in stack. That would reasonably assure that your stack is working correctly. Am I missing something?</p>
<p>Overall I agree that creating a side-effect-free non-trivial object is harder than isolated functions or FP-oriented code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-104</link>
		<dc:creator>Patrick</dc:creator>
		<pubDate>Fri, 14 Dec 2007 21:47:07 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-104</guid>
		<description>Sam Kong made an excellent point. Objects should share instance variables and thus be far from side-effect free. Making code more testable is more about function breakup than anything else. When I'm testing my classes, I make sure I can figure out (manually) the state of my object after a given function call. That way, all I have to do is pass the object, run the test, and compare the object to truth. Done.</description>
		<content:encoded><![CDATA[<p>Sam Kong made an excellent point. Objects should share instance variables and thus be far from side-effect free. Making code more testable is more about function breakup than anything else. When I&#8217;m testing my classes, I make sure I can figure out (manually) the state of my object after a given function call. That way, all I have to do is pass the object, run the test, and compare the object to truth. Done.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Golick</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-102</link>
		<dc:creator>James Golick</dc:creator>
		<pubDate>Fri, 14 Dec 2007 20:46:09 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-102</guid>
		<description>Great article, Mat!

I am often asked: "How can I test this method - it's untestable/too hard to test?" The implication, there, is that testing is too hard or impossible in certain situations. While the asker of said question is often right, the (un)testability of the code in question is nearly always a result of problematic design. When code is written without consideration for testing, it becomes easy to get trapped in a mess of untestable code. It makes sense - if you're not thinking about it, why would your code turn out testable?

Testing is a necessity (no space to prove that statement here), so testability is a requirement. If your code is untestable, you haven't met the testability requirement. No matter what you think of it, test driven development is a near sure fire way to ensure testability. Because you write your tests first, you can't (or are far less likely to) trap yourself in a an untestable situation.

As far as side effects are concerned, with respect to classes, just treat the internal state of the class as though it were the method's parameters, and return values. Whether the input comes from a class-scope variable, or is passed in to the method through arguments is irrelevant. Find a way to reproduce each potential situation in isolation (typically using mocking). Mock out any external dependencies. Then, you'll have a side-effect free method (effectively).</description>
		<content:encoded><![CDATA[<p>Great article, Mat!</p>
<p>I am often asked: &#8220;How can I test this method - it&#8217;s untestable/too hard to test?&#8221; The implication, there, is that testing is too hard or impossible in certain situations. While the asker of said question is often right, the (un)testability of the code in question is nearly always a result of problematic design. When code is written without consideration for testing, it becomes easy to get trapped in a mess of untestable code. It makes sense - if you&#8217;re not thinking about it, why would your code turn out testable?</p>
<p>Testing is a necessity (no space to prove that statement here), so testability is a requirement. If your code is untestable, you haven&#8217;t met the testability requirement. No matter what you think of it, test driven development is a near sure fire way to ensure testability. Because you write your tests first, you can&#8217;t (or are far less likely to) trap yourself in a an untestable situation.</p>
<p>As far as side effects are concerned, with respect to classes, just treat the internal state of the class as though it were the method&#8217;s parameters, and return values. Whether the input comes from a class-scope variable, or is passed in to the method through arguments is irrelevant. Find a way to reproduce each potential situation in isolation (typically using mocking). Mock out any external dependencies. Then, you&#8217;ll have a side-effect free method (effectively).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas Bernauer</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-101</link>
		<dc:creator>Andreas Bernauer</dc:creator>
		<pubDate>Fri, 14 Dec 2007 20:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-101</guid>
		<description>I did not find this very helpful. Yes, it is trivial to test side-effect free functions such as &lt;code&gt;sqrt&lt;/code&gt;. But IMHO you fail to explain how to actually extra "the juicy bits" of my program into a side-effect-free function?

For example, if you want to test an implementation of a stack, I don't quite see, how you can implement this side-effect free. Unless, you use a functional programming language in the first place, of course.</description>
		<content:encoded><![CDATA[<p>I did not find this very helpful. Yes, it is trivial to test side-effect free functions such as <code>sqrt</code>. But IMHO you fail to explain how to actually extra &#8220;the juicy bits&#8221; of my program into a side-effect-free function?</p>
<p>For example, if you want to test an implementation of a stack, I don&#8217;t quite see, how you can implement this side-effect free. Unless, you use a functional programming language in the first place, of course.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: webmat</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-100</link>
		<dc:creator>webmat</dc:creator>
		<pubDate>Fri, 14 Dec 2007 17:27:27 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-100</guid>
		<description>@James, @Sam Kong
I'll have to make a follow-up post on using static methods to advertise that code is side effect free (only to a certain extent, static members and other objects can still be affected). It's a method I've been using and I'd like to talk about it in more details.
I especially like it because it offers a small guarantee, but it saves me from totally abstracting it from the current class and putting it in a library. Not all code should be made shareable, especially not up front, when there is no immediate benefit.
This method allows you to separate it without too much effort, and only when you realise it could be made available elsewhere you can come back, extract it and generalise it a bit more.</description>
		<content:encoded><![CDATA[<p>@James, @Sam Kong<br />
I&#8217;ll have to make a follow-up post on using static methods to advertise that code is side effect free (only to a certain extent, static members and other objects can still be affected). It&#8217;s a method I&#8217;ve been using and I&#8217;d like to talk about it in more details.<br />
I especially like it because it offers a small guarantee, but it saves me from totally abstracting it from the current class and putting it in a library. Not all code should be made shareable, especially not up front, when there is no immediate benefit.<br />
This method allows you to separate it without too much effort, and only when you realise it could be made available elsewhere you can come back, extract it and generalise it a bit more.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: webmat</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-99</link>
		<dc:creator>webmat</dc:creator>
		<pubDate>Fri, 14 Dec 2007 17:19:56 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-99</guid>
		<description>Oh, and Pete, if you implemented a working game in 6 hours, I can guarantee you that your premise is wrong: you're not stupid ;-)</description>
		<content:encoded><![CDATA[<p>Oh, and Pete, if you implemented a working game in 6 hours, I can guarantee you that your premise is wrong: you&#8217;re not stupid ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: webmat</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-92</link>
		<dc:creator>webmat</dc:creator>
		<pubDate>Fri, 14 Dec 2007 17:16:11 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-92</guid>
		<description>@Pete, @Localhost,
Automated testing has many goals, here are 2:
- The most important reason for automated testing for me is to have tests that check continually (with no effort on my or my team's part) that everything still works as before. This ties in to what Localhost is saying.
- In a TDD approach, you define the expected behavior, then implement it. The benefits are often debated. I'm interested in it, but haven't had a chance to use the approach extensively yet. If you want to read more on the approach, just search Google or read more of Jame's articles (mentioned at the beginning of the post).</description>
		<content:encoded><![CDATA[<p>@Pete, @Localhost,<br />
Automated testing has many goals, here are 2:<br />
- The most important reason for automated testing for me is to have tests that check continually (with no effort on my or my team&#8217;s part) that everything still works as before. This ties in to what Localhost is saying.<br />
- In a TDD approach, you define the expected behavior, then implement it. The benefits are often debated. I&#8217;m interested in it, but haven&#8217;t had a chance to use the approach extensively yet. If you want to read more on the approach, just search Google or read more of Jame&#8217;s articles (mentioned at the beginning of the post).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: webmat</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-91</link>
		<dc:creator>webmat</dc:creator>
		<pubDate>Fri, 14 Dec 2007 17:10:50 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-91</guid>
		<description>@James, @Chris
I agree with Chris, in that if testing a given class is so tiedous, the design is probably at fault to a certain extent.
For very central classes, sometimes it's very difficult to reduce the coupling, however. But there are also techniques such as mocking (to stub, or fake some dependencies) which can help in these cases.
I don't agree with the "so many people do it" part, however ;-)</description>
		<content:encoded><![CDATA[<p>@James, @Chris<br />
I agree with Chris, in that if testing a given class is so tiedous, the design is probably at fault to a certain extent.<br />
For very central classes, sometimes it&#8217;s very difficult to reduce the coupling, however. But there are also techniques such as mocking (to stub, or fake some dependencies) which can help in these cases.<br />
I don&#8217;t agree with the &#8220;so many people do it&#8221; part, however ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Kong</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-93</link>
		<dc:creator>Sam Kong</dc:creator>
		<pubDate>Fri, 14 Dec 2007 16:58:10 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-93</guid>
		<description>Interesting article.

I once tried this approach myself but eventually gave it up.

In OOP language, side-effect-free methods break the rule of "low coupling, high cohesion".
Methods in an object should be cohesive to each other, which means that they should share instance variables.
Math.sqrt is a static method and doesn't have to be cohesive.

More concretely, if methods are not cohesive, they will unnecessarily have more parameters like in procedural language.</description>
		<content:encoded><![CDATA[<p>Interesting article.</p>
<p>I once tried this approach myself but eventually gave it up.</p>
<p>In OOP language, side-effect-free methods break the rule of &#8220;low coupling, high cohesion&#8221;.<br />
Methods in an object should be cohesive to each other, which means that they should share instance variables.<br />
Math.sqrt is a static method and doesn&#8217;t have to be cohesive.</p>
<p>More concretely, if methods are not cohesive, they will unnecessarily have more parameters like in procedural language.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: localhost</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-94</link>
		<dc:creator>localhost</dc:creator>
		<pubDate>Fri, 14 Dec 2007 16:31:16 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-94</guid>
		<description>@Pete

"Maybe I am stupid but I see only one use case for a test - that is to ensure that your application is running as expected on other machines as well. I dont believe that anyone who does intensive testing wasn’t a professional coder who has to use tests anyway for various reasons."

On a large application with a lot of developers, you'd be surprised how easy it is to change a single function and break your application in completely unexpected places,  many of which you've probably never even seen before. Having a strict automated nightly build process in conjunction with unit tests is basically the only way you can control this with any confidence - it is impossible to re-test everything by hand every time a change gets made. Writing decent tests ma seem like a waste of time if you're working in a small team, but it can save weeks/months on larger projects.</description>
		<content:encoded><![CDATA[<p>@Pete</p>
<p>&#8220;Maybe I am stupid but I see only one use case for a test - that is to ensure that your application is running as expected on other machines as well. I dont believe that anyone who does intensive testing wasn’t a professional coder who has to use tests anyway for various reasons.&#8221;</p>
<p>On a large application with a lot of developers, you&#8217;d be surprised how easy it is to change a single function and break your application in completely unexpected places,  many of which you&#8217;ve probably never even seen before. Having a strict automated nightly build process in conjunction with unit tests is basically the only way you can control this with any confidence - it is impossible to re-test everything by hand every time a change gets made. Writing decent tests ma seem like a waste of time if you&#8217;re working in a small team, but it can save weeks/months on larger projects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Danno</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-95</link>
		<dc:creator>Danno</dc:creator>
		<pubDate>Fri, 14 Dec 2007 16:26:49 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-95</guid>
		<description>It's also easier to test when you take testing into account from the beginning.  Leads to writing objects with less complex internal state that is more easily setup with mocks and stubs.</description>
		<content:encoded><![CDATA[<p>It&#8217;s also easier to test when you take testing into account from the beginning.  Leads to writing objects with less complex internal state that is more easily setup with mocks and stubs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Hartjes</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-97</link>
		<dc:creator>Chris Hartjes</dc:creator>
		<pubDate>Fri, 14 Dec 2007 16:09:44 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-97</guid>
		<description>@James

"Anyone who has tried to test a sufficiently complex class will find that the amount of work to set-up the internal state of an object to test a single use-case for a method prevents even the most keen programmer from doing so."

Sounds like poor class design or laziness on the part of the developer.  The reason most developers don't want to create repeatable tests (and I am guilty of this as well) is that it's boring.   Not testing stuff because "it's a lot of work to set it up" is the same as a little kid stamping his foot on the ground and saying "I don't wanna!" when asked to clean his room.

If writing tests in OOP languages is so useless, why do so many people do it?</description>
		<content:encoded><![CDATA[<p>@James</p>
<p>&#8220;Anyone who has tried to test a sufficiently complex class will find that the amount of work to set-up the internal state of an object to test a single use-case for a method prevents even the most keen programmer from doing so.&#8221;</p>
<p>Sounds like poor class design or laziness on the part of the developer.  The reason most developers don&#8217;t want to create repeatable tests (and I am guilty of this as well) is that it&#8217;s boring.   Not testing stuff because &#8220;it&#8217;s a lot of work to set it up&#8221; is the same as a little kid stamping his foot on the ground and saying &#8220;I don&#8217;t wanna!&#8221; when asked to clean his room.</p>
<p>If writing tests in OOP languages is so useless, why do so many people do it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-96</link>
		<dc:creator>James</dc:creator>
		<pubDate>Fri, 14 Dec 2007 14:41:59 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-96</guid>
		<description>basically - what you are saying is "in order to unit test your program, use a functional programming language".  The whole idea of OOP is to take into account the state of an object within methods.  In fact, methods on objects are &lt;i&gt;useless&lt;/i&gt; unless they take into account that state (otherwise you would make them static class functions).

Testing OOP languages is almost useless (IMO) since every method by definition should either alter state or return different results based on state.  Anyone who has tried to test a sufficiently complex class will find that the amount of work to set-up the internal state of an object to test a single use-case for a method prevents even the most keen programmer from doing so.</description>
		<content:encoded><![CDATA[<p>basically - what you are saying is &#8220;in order to unit test your program, use a functional programming language&#8221;.  The whole idea of OOP is to take into account the state of an object within methods.  In fact, methods on objects are <i>useless</i> unless they take into account that state (otherwise you would make them static class functions).</p>
<p>Testing OOP languages is almost useless (IMO) since every method by definition should either alter state or return different results based on state.  Anyone who has tried to test a sufficiently complex class will find that the amount of work to set-up the internal state of an object to test a single use-case for a method prevents even the most keen programmer from doing so.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pete</title>
		<link>http://programblings.com/2007/12/13/an-easy-way-to-make-your-code-more-testable/#comment-98</link>
		<dc:creator>pete</dc:creator>
		<pubDate>Fri, 14 Dec 2007 12:35:28 +0000</pubDate>
		<guid isPermaLink="false">http://programblings.com/?p=30#comment-98</guid>
		<description>Maybe I am stupid but I see only one use case for a test - that is to ensure that your application is running as expected on other machines as well. I dont believe that anyone who does intensive testing wasn't a professional coder who has to use tests anyway for various reasons.

But when I actually go and read test stuff for a programming language, they seem to rather focus their minds on the whole testing aspect.
Do they not allow that, if you use objects for a long time in their "expected" use area, these object will specifically work very well, simply because author(s) improved them over time?

Recently a few of us (3) finished a small game project. It was inspired by a python blog, where someone wrote about a 48 hours game project (ours was only 6 hours but it was still interesting).

There were 0 tests involved, but the game works (has only 12 .rb files and about 16 classes).</description>
		<content:encoded><![CDATA[<p>Maybe I am stupid but I see only one use case for a test - that is to ensure that your application is running as expected on other machines as well. I dont believe that anyone who does intensive testing wasn&#8217;t a professional coder who has to use tests anyway for various reasons.</p>
<p>But when I actually go and read test stuff for a programming language, they seem to rather focus their minds on the whole testing aspect.<br />
Do they not allow that, if you use objects for a long time in their &#8220;expected&#8221; use area, these object will specifically work very well, simply because author(s) improved them over time?</p>
<p>Recently a few of us (3) finished a small game project. It was inspired by a python blog, where someone wrote about a 48 hours game project (ours was only 6 hours but it was still interesting).</p>
<p>There were 0 tests involved, but the game works (has only 12 .rb files and about 16 classes).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
