<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;action=history&amp;feed=atom</id>
		<title>Improved Testability Leads to Better Design - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;action=history&amp;feed=atom"/>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;action=history"/>
		<updated>2013-05-20T00:50:33Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.11.0</generator>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25155&amp;oldid=prev</id>
		<title>Kevlin: Economic Testability moved to Improved Testability Leads to Better Design</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25155&amp;oldid=prev"/>
				<updated>2009-08-06T14:40:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;a href=&quot;/wiki/index.php/Economic_Testability&quot; title=&quot;Economic Testability&quot;&gt;Economic Testability&lt;/a&gt; moved to &lt;a href=&quot;/wiki/index.php/Improved_Testability_Leads_to_Better_Design&quot; title=&quot;Improved Testability Leads to Better Design&quot;&gt;Improved Testability Leads to Better Design&lt;/a&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 14:40, 6 August 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25090&amp;oldid=prev</id>
		<title>Kevlin at 17:13, 4 August 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25090&amp;oldid=prev"/>
				<updated>2009-08-04T17:13:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 17:13, 4 August 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 5:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 5:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Progressive testing is often stymied because certain necessary functions have not yet been implemented. For example, a common occurrence involves an object that needs to be tested, but makes use of a yet-to-be-built object. An incompleteness that means the test cannot be run. A way around this is to allow the provision of the yet-to-be-built object via a parametrized constructor: When testing we can provide a test double object without changing the internals at all; in the production code we can provide the real (tested) object to deliver the required functionality. The API of the test double and the production object are identical and the object under test is unaware of whether it is running in a test or a production environment.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Progressive testing is often stymied because certain necessary functions have not yet been implemented. For example, a common occurrence involves an object that needs to be tested, but makes use of a yet-to-be-built object. An incompleteness that means the test cannot be run. A way around this is to allow the provision of the yet-to-be-built object via a parametrized constructor: When testing we can provide a test double object without changing the internals at all; in the production code we can provide the real (tested) object to deliver the required functionality. The API of the test double and the production object are identical and the object under test is unaware of whether it is running in a test or a production environment.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &amp;amp;mdash; a lot further. This very soft style of building systems brings advantages all down the line when compared to the hard-wired logic commonly encountered &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;in code&lt;/ins&gt;. For example, if we need to introduce some kind of logging trail for complex bug diagnosis during development, we can provide the logging logic via &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the constructor parameters, using &lt;/ins&gt;the plug-in technique &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;already &lt;/ins&gt;outlined. In production, using the ''null object'' pattern (which will provide a &amp;quot;do nothing&amp;quot; object with the same API as the logger), we can replace the logger with a harmless null alternative. This &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;means &lt;/ins&gt;of course that the code being monitored is unchanged, an important point for some types of bug. Should it be necessary that you dynamically enable logging in production mode, this technique makes it very simple to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;enable or disable &lt;/ins&gt;logging &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;dynamically &amp;amp;mdash; &lt;/ins&gt;or indeed anything else that you need. Then we have a production system that gracefully slips into logging mode when needed. It may be unfortunate that you should need to do this, but if you do, then sensible application of these techniques can be seriously reputation enhancing!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &amp;amp;mdash; a lot further. This very soft style of building systems brings advantages all down the line when compared to the hard-wired logic &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;which is &lt;/del&gt;commonly encountered. For example, if we need to introduce some kind of logging trail for complex bug diagnosis during development, we can provide the logging logic via the plug-in technique outlined &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;above, via the constructor parameters&lt;/del&gt;. In production, using the ''null object'' pattern (which will provide a &amp;quot;do nothing&amp;quot; object with the same API as the logger), we can replace the logger with a harmless null alternative. This &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;meams &lt;/del&gt;of course that the code being &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;logged / &lt;/del&gt;monitored is unchanged, an important point for some types of bug. Should it be necessary that you dynamically enable logging in production mode, this technique makes it very simple to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;control the dynamically switch / on off dynamic &lt;/del&gt;logging &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(&lt;/del&gt;or indeed anything else that you need&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;)&lt;/del&gt;. Then we have a production system that gracefully slips into logging mode when needed. It may be unfortunate that you should need to do this, but if you do, then sensible application of these techniques can be seriously reputation&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/del&gt;enhancing&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;!&lt;/del&gt;!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25089&amp;oldid=prev</id>
		<title>Gbcambridge at 13:58, 4 August 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25089&amp;oldid=prev"/>
				<updated>2009-08-04T13:58:32Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 13:58, 4 August 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &amp;amp;mdash; a lot further. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If &lt;/del&gt;we need to introduce some kind of logging trail for complex bug diagnosis during development, we can provide the logging logic via the plug-in technique outlined above, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;providing the logging object in &lt;/del&gt;the constructor parameters. In production, using the ''null object'' pattern (which will provide a &amp;quot;do nothing&amp;quot; object with the same API as the logger), we can replace the logger with a harmless null alternative. This meams of course that the code being logged / monitored is unchanged, an important point for some types of bug. Should it be necessary that you dynamically enable logging in production mode, this technique makes it very simple to control the dynamically switch / on off dynamic logging (or indeed anything else that you need). Then we have a production system that gracefully slips into logging mode when needed. It may be unfortunate that you should need to do this, but if you do, then sensible application of these techniques can be seriously reputation-enhancing!!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &amp;amp;mdash; a lot further. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;This very soft style of building systems brings advantages all down the line when compared to the hard-wired logic which is commonly encountered. For example, if &lt;/ins&gt;we need to introduce some kind of logging trail for complex bug diagnosis during development, we can provide the logging logic via the plug-in technique outlined above, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;via &lt;/ins&gt;the constructor parameters. In production, using the ''null object'' pattern (which will provide a &amp;quot;do nothing&amp;quot; object with the same API as the logger), we can replace the logger with a harmless null alternative. This meams of course that the code being logged / monitored is unchanged, an important point for some types of bug. Should it be necessary that you dynamically enable logging in production mode, this technique makes it very simple to control the dynamically switch / on off dynamic logging (or indeed anything else that you need). Then we have a production system that gracefully slips into logging mode when needed. It may be unfortunate that you should need to do this, but if you do, then sensible application of these techniques can be seriously reputation-enhancing!!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:25084:newid:25089 --&gt;
&lt;/table&gt;</summary>
		<author><name>Gbcambridge</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25084&amp;oldid=prev</id>
		<title>Gbcambridge at 16:02, 2 August 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25084&amp;oldid=prev"/>
				<updated>2009-08-02T16:02:42Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 16:02, 2 August 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;''Economic Testability'' is a simple concept yet one seen infrequently in practice. Essentially, it boils down to recognizing that since code-testing should be a requirement and that we have in place some nice, economical, standard tools for testing (such as xUnit, Fit, etc.), then the products that we build should always satisfy the requirement of ease-of-test in addition to any other requirements. Happily the ease-of-test requirement reinforces rather than contradicts best practice.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;''Economic Testability'' is a simple concept yet one seen infrequently in practice. Essentially, it boils down to recognizing that since code-testing should be a requirement and that we have in place some nice, economical, standard tools for testing (such as xUnit, Fit, etc.), then the products that we build should always satisfy the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;new &lt;/ins&gt;requirement of ease-of-test&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;in addition to any other requirements. Happily the ease-of-test requirement reinforces rather than contradicts best practice&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If you build your systems so that testing is made economic  &amp;amp;mdash; while simultaneously of course preserving simplicity in the production model &amp;amp;mdash; the interfaces that you finally end up with are likely to be greatly improved over the one-environment system. Code which has to operate successfully and unchanged in two or more environments (the test and production environments) must pay more than lip service to clean interfaces and maximum encapsulation if the task of embedding within the multiple environments is not to become overwhelming. The discipline needed leads to better design and more modular construction. It really is a win&amp;amp;ndash;win situation&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Progressive testing is often stymied because certain necessary functions have not yet been implemented. For example, a common occurrence involves an object that needs to be tested, but makes use of a yet-to-be-built object. An incompleteness that means the test cannot be run. A way around this is to allow the provision of the yet-to-be-built object via a parametrized constructor: When testing we can provide a test double object without changing the internals at all; in the production code we can provide the real (tested) object to deliver the required functionality. The API of the test double and the production object are identical and the object under test is unaware of whether it is running in a test or a production environment.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Progressive testing is often stymied because certain necessary functions have not yet been implemented. For example, a common occurrence involves an object that needs to be tested, but makes use of a yet-to-be-built object. An incompleteness that means the test cannot be run. A way around this is to allow the provision of the yet-to-be-built object via a parametrized constructor: When testing we can provide a test double object without changing the internals at all; in the production code we can provide the real (tested) object to deliver the required functionality. The API of the test double and the production object are identical and the object under test is unaware of whether it is running in a test or a production environment.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &amp;amp;mdash; a lot further. If we need to introduce some kind of logging trail for complex bug diagnosis, we can provide the logging logic via the plug-in technique outlined above, providing the logging object in the constructor parameters. In production, using the ''null object'' pattern (which will provide a &amp;quot;do nothing&amp;quot; object with the same API as the logger), we can replace the logger with a harmless null alternative. If it is possible that you need to dynamically enable logging in production mode, this technique makes it very simple. Then we have a production system that gracefully slips into logging mode when needed. It may be unfortunate that you should need to do this, but if you do, then you can look like a hero, i.e., a professional!&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If you build your systems so that testing is made economic  &amp;amp;mdash; while simultaneously &lt;/del&gt;of course &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;preserving simplicity in the production model &lt;/del&gt;&amp;amp;mdash; &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the interfaces that you finally end up with are likely &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;be greatly improved over &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;one&lt;/del&gt;-&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;environment system. Code which has to operate successfully and unchanged &lt;/del&gt;in &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;two or more environments (&lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;test and &lt;/del&gt;production &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;environments&lt;/del&gt;) &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;must pay more than lip service to clean interfaces and maximum encapsulation if &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;task &lt;/del&gt;of &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;embedding within &lt;/del&gt;the &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;multiple environments &lt;/del&gt;is &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;not to become overwhelming&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;The discipline needed leads &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;better design and more modular construction&lt;/del&gt;. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It really is &lt;/del&gt;a &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;win&amp;amp;ndash;win situation&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;We can go further &lt;/ins&gt;of course &amp;amp;mdash; &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a lot further. If we need &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;introduce some kind of logging trail for complex bug diagnosis during development, we can provide &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;logging logic via the plug&lt;/ins&gt;-in &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;technique outlined above, providing &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;logging object in the constructor parameters. In &lt;/ins&gt;production&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, using the ''null object'' pattern (which will provide a &amp;quot;do nothing&amp;quot; object with the same API as the logger&lt;/ins&gt;)&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, we can replace &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;logger with a harmless null alternative. This meams &lt;/ins&gt;of &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;course that &lt;/ins&gt;the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;code being logged / monitored &lt;/ins&gt;is &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;unchanged, an important point for some types of bug&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Should it be necessary that you dynamically enable logging in production mode, this technique makes it very simple &lt;/ins&gt;to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;control the dynamically switch / on off dynamic logging (or indeed anything else that you need)&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Then we have &lt;/ins&gt;a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;production system that gracefully slips into logging mode when needed&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It may be unfortunate that you should need to do this, but if you do, then sensible application of these techniques can be seriously reputation-enhancing!!&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;#160;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[George Brooke]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[George Brooke]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:25069:newid:25084 --&gt;
&lt;/table&gt;</summary>
		<author><name>Gbcambridge</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25069&amp;oldid=prev</id>
		<title>Kevlin at 13:46, 1 August 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25069&amp;oldid=prev"/>
				<updated>2009-08-01T13:46:32Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 13:46, 1 August 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;''Economic Testability'' is a simple concept &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;but infrequently &lt;/del&gt;seen in practice. Essentially it boils down to recognizing that since code-testing should be a requirement and that we have in place some nice, economical, standard tools for testing (such as xUnit, Fit, etc.), then the products that we build should always satisfy the requirement of ease-of-test in addition to any other requirements. Happily the ease-of-test requirement reinforces rather than contradicts best practice.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;''Economic Testability'' is a simple concept &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;yet one &lt;/ins&gt;seen &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;infrequently &lt;/ins&gt;in practice. Essentially&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;it boils down to recognizing that since code-testing should be a requirement and that we have in place some nice, economical, standard tools for testing (such as xUnit, Fit, etc.), then the products that we build should always satisfy the requirement of ease-of-test in addition to any other requirements. Happily the ease-of-test requirement reinforces rather than contradicts best practice.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Progressive testing is often stymied because certain necessary functions have not yet been implemented. For example, an object needs to be tested but &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;it &lt;/del&gt;makes use of a yet-to-be-built object &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is a pretty common occurrence&lt;/del&gt;. A way around this is to allow the provision of the yet-to-be-built object via a parametrized constructor: When testing we can provide a test double object without changing the internals at all; in the production code we can provide the real (tested) object to deliver the required functionality. The API of the test double and the production object are identical and the object under test is unaware of whether it is running in a test or a production environment.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Progressive testing is often stymied because certain necessary functions have not yet been implemented. For example, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a common occurrence involves &lt;/ins&gt;an object &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that &lt;/ins&gt;needs to be tested&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;but makes use of a yet-to-be-built object&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. An incompleteness that means the test cannot be run&lt;/ins&gt;. A way around this is to allow the provision of the yet-to-be-built object via a parametrized constructor: When testing we can provide a test double object without changing the internals at all; in the production code we can provide the real (tested) object to deliver the required functionality. The API of the test double and the production object are identical and the object under test is unaware of whether it is running in a test or a production environment.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &amp;amp;mdash; a lot further. If we need to introduce some kind of logging trail for complex bug diagnosis, we can provide the logging logic via the plug-in technique outlined above, providing the logging object in the constructor parameters. In production, using the ''null object'' pattern (which will provide a &amp;quot;do&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/del&gt;nothing&amp;quot; object with the same API as the logger), we can replace the logger with a harmless null&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/del&gt;alternative. If it is possible that you need to dynamically enable logging in production mode, this technique makes it very simple. Then we have a production system that gracefully slips into logging mode when needed. It may be unfortunate that you should need to do this, but if you do, then you can look like a hero, i.e., a professional!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &amp;amp;mdash; a lot further. If we need to introduce some kind of logging trail for complex bug diagnosis, we can provide the logging logic via the plug-in technique outlined above, providing the logging object in the constructor parameters. In production, using the ''null object'' pattern (which will provide a &amp;quot;do nothing&amp;quot; object with the same API as the logger), we can replace the logger with a harmless null alternative. If it is possible that you need to dynamically enable logging in production mode, this technique makes it very simple. Then we have a production system that gracefully slips into logging mode when needed. It may be unfortunate that you should need to do this, but if you do, then you can look like a hero, i.e., a professional!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you build your systems so that testing is made economic  &amp;amp;mdash; while simultaneously of course preserving simplicity in the production model &amp;amp;mdash; the interfaces that you finally end up with are likely to be greatly improved over the one-environment system. Code which has to operate successfully and unchanged in two or more environments (the test and production environments) must pay more than lip&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/del&gt;service to clean interfaces and maximum encapsulation if the task of embedding within the multiple environments is not to become overwhelming. The discipline needed leads to better design and more modular construction. It really is a win&amp;amp;ndash;win situation.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you build your systems so that testing is made economic  &amp;amp;mdash; while simultaneously of course preserving simplicity in the production model &amp;amp;mdash; the interfaces that you finally end up with are likely to be greatly improved over the one-environment system. Code which has to operate successfully and unchanged in two or more environments (the test and production environments) must pay more than lip service to clean interfaces and maximum encapsulation if the task of embedding within the multiple environments is not to become overwhelming. The discipline needed leads to better design and more modular construction. It really is a win&amp;amp;ndash;win situation.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[George Brooke]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[George Brooke]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:25049:newid:25069 --&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25049&amp;oldid=prev</id>
		<title>Gbcambridge at 15:54, 31 July 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25049&amp;oldid=prev"/>
				<updated>2009-07-31T15:54:48Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 15:54, 31 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;''Economic Testability'' is a simple concept but &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;not one often &lt;/del&gt;seen in practice. Essentially it boils down to recognizing that since &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;tested &lt;/del&gt;code should be a requirement&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/del&gt;and that we have in place some nice, economical, standard tools for testing (such as xUnit, Fit, etc.), then the products that we build should always satisfy the requirement of ease-of-test in addition to other requirements. Happily &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;this &lt;/del&gt;requirement reinforces rather than contradicts best practice.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;''Economic Testability'' is a simple concept but &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;infrequently &lt;/ins&gt;seen in practice. Essentially it boils down to recognizing that since code&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-testing &lt;/ins&gt;should be a requirement and that we have in place some nice, economical, standard tools for testing (such as xUnit, Fit, etc.), then the products that we build should always satisfy the requirement of ease-of-test in addition to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;any &lt;/ins&gt;other requirements. Happily &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the ease-of-test &lt;/ins&gt;requirement reinforces rather than contradicts best practice.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Progressive testing is often stymied because certain &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;major &lt;/del&gt;functions have not yet been implemented. For example, an object needs to be tested but it makes use of a yet-to-be-built object is a pretty common occurrence. A way around this is to allow the provision of the yet-to-be-built object via a &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;parameterized &lt;/del&gt;constructor: When testing we can provide a &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;dummy &lt;/del&gt;object without changing the internals at all; in the production code we can provide the real (tested) object to deliver the required functionality. The &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;actual method signatures &lt;/del&gt;are &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;unchanged &lt;/del&gt;and the object under test is unaware of whether it is running in a test or a production environment.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Progressive testing is often stymied because certain &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;necessary &lt;/ins&gt;functions have not yet been implemented. For example, an object needs to be tested but it makes use of a yet-to-be-built object is a pretty common occurrence. A way around this is to allow the provision of the yet-to-be-built object via a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;parametrized &lt;/ins&gt;constructor: When testing we can provide a &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;test double &lt;/ins&gt;object without changing the internals at all; in the production code we can provide the real (tested) object to deliver the required functionality. The &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;API of the test double and the production object &lt;/ins&gt;are &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;identical &lt;/ins&gt;and the object under test is unaware of whether it is running in a test or a production environment.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &amp;amp;mdash; a lot further. If we &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;wanted &lt;/del&gt;to introduce some kind of logging trail for complex bug diagnosis, we can provide the logging logic via the plug-in technique outlined above, providing the logging object in the constructor parameters. In production, using the ''null object'' pattern, we can replace the logger with a harmless alternative. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;On the other hand&lt;/del&gt;, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;why not make &lt;/del&gt;this &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;dynamically selectable? &lt;/del&gt;Then we &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;would &lt;/del&gt;have a production system that &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;could &lt;/del&gt;gracefully &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;slip &lt;/del&gt;into logging mode. It may be unfortunate that you should need to do this, but if you do, then you can look like a hero, i.e., a professional!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &amp;amp;mdash; a lot further. If we &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;need &lt;/ins&gt;to introduce some kind of logging trail for complex bug diagnosis, we can provide the logging logic via the plug-in technique outlined above, providing the logging object in the constructor parameters. In production, using the ''null object'' pattern &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;(which will provide a &amp;quot;do-nothing&amp;quot; object with the same API as the logger)&lt;/ins&gt;, we can replace the logger with a harmless &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;null-&lt;/ins&gt;alternative. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If it is possible that you need to dynamically enable logging in production mode&lt;/ins&gt;, this &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;technique makes it very simple. &lt;/ins&gt;Then we have a production system that gracefully &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;slips &lt;/ins&gt;into logging mode &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;when needed&lt;/ins&gt;. It may be unfortunate that you should need to do this, but if you do, then you can look like a hero, i.e., a professional!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you build your systems so that testing is made &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;simple &lt;/del&gt;&amp;amp;mdash; while simultaneously of course preserving simplicity in the production model &amp;amp;mdash; the interfaces that you finally end up with &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is &lt;/del&gt;likely to be greatly improved. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It is superior &lt;/del&gt;in &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;terms of encapsulation &lt;/del&gt;and &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;portability &lt;/del&gt;than if &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;you had built you system with just one target environment in mind&lt;/del&gt;. The discipline &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;involved in creating an interface that is equally at home in two environments causes you &lt;/del&gt;to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;do a &lt;/del&gt;better &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;job in the &lt;/del&gt;design &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;essentials than otherwise&lt;/del&gt;. It really is a win&amp;amp;ndash;win situation.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;If you build your systems so that testing is made &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;economic  &lt;/ins&gt;&amp;amp;mdash; while simultaneously of course preserving simplicity in the production model &amp;amp;mdash; the interfaces that you finally end up with &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are &lt;/ins&gt;likely to be greatly improved &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;over the one-environment system&lt;/ins&gt;. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Code which has to operate successfully and unchanged &lt;/ins&gt;in &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;two or more environments (the test &lt;/ins&gt;and &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;production environments) must pay more &lt;/ins&gt;than &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;lip-service to clean interfaces and maximum encapsulation &lt;/ins&gt;if &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the task of embedding within the multiple environments is not to become overwhelming&lt;/ins&gt;. The discipline &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;needed leads &lt;/ins&gt;to better design &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;and more modular construction&lt;/ins&gt;. It really is a win&amp;amp;ndash;win situation.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[George Brooke]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[George Brooke]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Gbcambridge</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25032&amp;oldid=prev</id>
		<title>Kevlin at 13:59, 30 July 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25032&amp;oldid=prev"/>
				<updated>2009-07-30T13:59:22Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 13:59, 30 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;''Economic Testability'' is a simple concept but not one often seen in practice. Essentially it boils down to recognizing that since tested code should be a requirement, and that we have in place some nice, economical, standard tools for testing (such as xUnit, Fit, etc.), then the products that we build should always satisfy the requirement of ease-of-test in addition to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;any &lt;/del&gt;other requirements. Happily this requirement reinforces rather than contradicts best practice. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Perhaps a few examples will help?&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;''Economic Testability'' is a simple concept but not one often seen in practice. Essentially it boils down to recognizing that since tested code should be a requirement, and that we have in place some nice, economical, standard tools for testing (such as xUnit, Fit, etc.), then the products that we build should always satisfy the requirement of ease-of-test in addition to other requirements. Happily this requirement reinforces rather than contradicts best practice.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;It &lt;/del&gt;is often &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the case that tests are impeded &lt;/del&gt;because certain major functions &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are &lt;/del&gt;not yet implemented. For example,an object needs to be tested but it makes use of a yet-to-be-built object is a pretty common occurrence. A way around this is to allow the provision of the yet-to-be-built object via a parameterized constructor&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. Then, in the test-case situation &lt;/del&gt;we can provide a dummy object without changing the internals at all; in the production &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;model &lt;/del&gt;we can provide the real (tested) object to deliver the required functionality. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;When implemented via the constructor, as recommended, in the set-up region of the tests, the &lt;/del&gt;actual method signatures are &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;not changed at all&lt;/del&gt;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Progressive testing &lt;/ins&gt;is often &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;stymied &lt;/ins&gt;because certain major functions &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;have &lt;/ins&gt;not yet &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;been &lt;/ins&gt;implemented. For example, an object needs to be tested but it makes use of a yet-to-be-built object is a pretty common occurrence. A way around this is to allow the provision of the yet-to-be-built object via a parameterized constructor&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;: When testing &lt;/ins&gt;we can provide a dummy object without changing the internals at all; in the production &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;code &lt;/ins&gt;we can provide the real (tested) object to deliver the required functionality. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;The &lt;/ins&gt;actual method signatures are &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;unchanged and the object under test is unaware of whether it is running in a test or a production environment&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;.. &lt;/del&gt;a lot further. If we wanted to introduce some kind of logging&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/del&gt;trail for complex bug diagnosis, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;then &lt;/del&gt;we can provide the logging logic via the technique outlined above, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;by &lt;/del&gt;providing the logging object in the constructor parameters. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;At &lt;/del&gt;production &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;time&lt;/del&gt;, using the null&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/del&gt;object pattern, we can replace the logger with a harmless alternative. On the other hand, why not make this dynamically selectable? Then we &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;could &lt;/del&gt;have a production system &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;which can &lt;/del&gt;gracefully slip into logging mode. It may be unfortunate that you should need to do this, but if you do, then you can look like a hero, i.e., a professional!&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;We can go further of course &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; &lt;/ins&gt;a lot further. If we wanted to introduce some kind of logging trail for complex bug diagnosis, we can provide the logging logic via the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;plug-in &lt;/ins&gt;technique outlined above, providing the logging object in the constructor parameters. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;In &lt;/ins&gt;production, using the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''&lt;/ins&gt;null object&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;'' &lt;/ins&gt;pattern, we can replace the logger with a harmless alternative. On the other hand, why not make this dynamically selectable? Then we &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;would &lt;/ins&gt;have a production system &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that could &lt;/ins&gt;gracefully slip into logging mode. It may be unfortunate that you should need to do this, but if you do, then you can look like a hero, i.e., a professional!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Finally, if &lt;/del&gt;you build your systems so that testing is made simple&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, either by following the suggestion here, or by just making the interfaces very simple to use in the xUnit world, and &lt;/del&gt;simultaneously of course preserving simplicity in the production model&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, then our experience has been that &lt;/del&gt;the interfaces that you finally end up with &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;are &lt;/del&gt;superior in terms of encapsulation and portability than if you had built you system with just one target environment in mind. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;In other words, the &lt;/del&gt;discipline in &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;building &lt;/del&gt;an interface &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;which &lt;/del&gt;is equally at home in two environments causes you to do a better job in the design&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/del&gt;essentials than otherwise. It really is a win&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;-&lt;/del&gt;win situation.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;If &lt;/ins&gt;you build your systems so that testing is made simple &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; while &lt;/ins&gt;simultaneously of course preserving simplicity in the production model &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;mdash; &lt;/ins&gt;the interfaces that you finally end up with &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is likely to be greatly improved. It is &lt;/ins&gt;superior in terms of encapsulation and portability than if you had built you system with just one target environment in mind. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;The &lt;/ins&gt;discipline &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;involved &lt;/ins&gt;in &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;creating &lt;/ins&gt;an interface &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;that &lt;/ins&gt;is equally at home in two environments causes you to do a better job in the design essentials than otherwise. It really is a win&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;amp;ndash;&lt;/ins&gt;win situation.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[George Brooke]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[George Brooke]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25031&amp;oldid=prev</id>
		<title>Kevlin at 11:59, 30 July 2009</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=25031&amp;oldid=prev"/>
				<updated>2009-07-30T11:59:56Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 11:59, 30 July 2009&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;quot;&lt;/del&gt;Economic Testability&lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;quot; &lt;/del&gt;is a simple concept but not often seen in practice. Essentially it boils down to &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;recognising &lt;/del&gt;that since tested code &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;is &lt;/del&gt;a requirement and that we have some nice, economical, &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;standards &lt;/del&gt;for testing &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;in place &lt;/del&gt;(such as xUnit, Fit, etc), then the products that we build should always satisfy the requirement of ease-of-test in addition to any other requirements. Happily this requirement &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;does not contradict, but &lt;/del&gt;reinforces best practice. Perhaps a few examples will help?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;''&lt;/ins&gt;Economic Testability&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;'' &lt;/ins&gt;is a simple concept but not &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;one &lt;/ins&gt;often seen in practice. Essentially it boils down to &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;recognizing &lt;/ins&gt;that since tested code &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;should be &lt;/ins&gt;a requirement&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;, &lt;/ins&gt;and that we have &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;in place &lt;/ins&gt;some nice, economical, &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;standard tools &lt;/ins&gt;for testing (such as xUnit, Fit, etc&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;.&lt;/ins&gt;), then the products that we build should always satisfy the requirement of ease-of-test in addition to any other requirements. Happily this requirement reinforces &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;rather than contradicts &lt;/ins&gt;best practice. Perhaps a few examples will help?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It is often the case that tests are impeded because certain major functions are not yet implemented. For example,an object needs to be tested but it makes use of a yet-to-be-built object is a pretty common occurrence. A way around this is to allow the provision of the yet-to-be-built object via a parameterized constructor. Then, in the test-case situation we can provide a dummy object without changing the internals at all; in the production model we can provide the real (tested) object to deliver the required functionality. When implemented via the constructor, as recommended, in the set-up region of the tests, the actual method signatures are not changed at all.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;It is often the case that tests are impeded because certain major functions are not yet implemented. For example,an object needs to be tested but it makes use of a yet-to-be-built object is a pretty common occurrence. A way around this is to allow the provision of the yet-to-be-built object via a parameterized constructor. Then, in the test-case situation we can provide a dummy object without changing the internals at all; in the production model we can provide the real (tested) object to deliver the required functionality. When implemented via the constructor, as recommended, in the set-up region of the tests, the actual method signatures are not changed at all.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Finally, if you build your systems so that testing is made simple, either by following the suggestion here, or by just making the interfaces very simple to use in the xUnit world, and simultaneously of course preserving simplicity in the production model, then our experience has been that the interfaces that you finally end up with are superior in terms of encapsulation and portability than if you had built you system with just one target environment in mind. In other words, the discipline in building an interface which is equally at home in two environments causes you to do a better job in the design-essentials than otherwise. It really is a win-win situation.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Finally, if you build your systems so that testing is made simple, either by following the suggestion here, or by just making the interfaces very simple to use in the xUnit world, and simultaneously of course preserving simplicity in the production model, then our experience has been that the interfaces that you finally end up with are superior in terms of encapsulation and portability than if you had built you system with just one target environment in mind. In other words, the discipline in building an interface which is equally at home in two environments causes you to do a better job in the design-essentials than otherwise. It really is a win-win situation.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;By [[George Brooke]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;This work is licensed under a [http://creativecommons.org/licenses/by/3.0/us/ Creative Commons Attribution 3] &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Back to [[97 Things Every Programmer Should Know]] home page&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key wikicontent:diff:version:1.11a:oldid:23588:newid:25031 --&gt;
&lt;/table&gt;</summary>
		<author><name>Kevlin</name></author>	</entry>

	<entry>
		<id>http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=23588&amp;oldid=prev</id>
		<title>Gbcambridge: Planning for testing will improve your overall design</title>
		<link rel="alternate" type="text/html" href="http://commons.oreilly.com/wiki/index.php?title=Improved_Testability_Leads_to_Better_Design&amp;diff=23588&amp;oldid=prev"/>
				<updated>2009-03-04T13:30:01Z</updated>
		
		<summary type="html">&lt;p&gt;Planning for testing will improve your overall design&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;quot;Economic Testability&amp;quot; is a simple concept but not often seen in practice. Essentially it boils down to recognising that since tested code is a requirement and that we have some nice, economical, standards for testing in place (such as xUnit, Fit, etc), then the products that we build should always satisfy the requirement of ease-of-test in addition to any other requirements. Happily this requirement does not contradict, but reinforces best practice. Perhaps a few examples will help?&lt;br /&gt;
&lt;br /&gt;
It is often the case that tests are impeded because certain major functions are not yet implemented. For example,an object needs to be tested but it makes use of a yet-to-be-built object is a pretty common occurrence. A way around this is to allow the provision of the yet-to-be-built object via a parameterized constructor. Then, in the test-case situation we can provide a dummy object without changing the internals at all; in the production model we can provide the real (tested) object to deliver the required functionality. When implemented via the constructor, as recommended, in the set-up region of the tests, the actual method signatures are not changed at all.&lt;br /&gt;
&lt;br /&gt;
We can go further of course .. a lot further. If we wanted to introduce some kind of logging-trail for complex bug diagnosis, then we can provide the logging logic via the technique outlined above, by providing the logging object in the constructor parameters. At production time, using the null-object pattern, we can replace the logger with a harmless alternative. On the other hand, why not make this dynamically selectable? Then we could have a production system which can gracefully slip into logging mode. It may be unfortunate that you should need to do this, but if you do, then you can look like a hero, i.e., a professional!&lt;br /&gt;
&lt;br /&gt;
Finally, if you build your systems so that testing is made simple, either by following the suggestion here, or by just making the interfaces very simple to use in the xUnit world, and simultaneously of course preserving simplicity in the production model, then our experience has been that the interfaces that you finally end up with are superior in terms of encapsulation and portability than if you had built you system with just one target environment in mind. In other words, the discipline in building an interface which is equally at home in two environments causes you to do a better job in the design-essentials than otherwise. It really is a win-win situation.&lt;/div&gt;</summary>
		<author><name>Gbcambridge</name></author>	</entry>

	</feed>