<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://commons.oreilly.com/wiki/skins/common/feed.css?97"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Test Precisely and Concretely - Revision history</title>
		<link>http://commons.oreilly.com/wiki/index.php?title=Test_Precisely_and_Concretely&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.11.0</generator>
		<lastBuildDate>Sat, 25 May 2013 13:45:49 GMT</lastBuildDate>
		<item>
			<title>Kevlin at 18:49, 5 July 2009</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Test_Precisely_and_Concretely&amp;diff=24604&amp;oldid=prev</link>
			<description>&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 18:49, 5 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: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Although it is important to test for desired, essential behavior rather than incidental behavior of an implementation, this should not be construed or mistaken as an excuse for vague tests. Tests need to be both accurate ''and'' precise.&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;Although it is important to test for desired, essential behavior rather than incidental behavior of an implementation, this should not be construed or mistaken as an excuse for vague tests. Tests need to be both accurate ''and'' precise.&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;Something of a tried and tested (and testing) classic, sorting routines provide an illustrative example. Implementing sorting &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;algorithms &lt;/del&gt;is not necessarily an everyday task for a programmer, but uses for sorting are sufficiently commonplace that the expectations for a sorting routine are familiar. This familiarity, however, often brings with it a false sense of knowledge.&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;Something of a tried and tested (and testing) classic, sorting routines provide an illustrative example. Implementing &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a &lt;/ins&gt;sorting &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;algorithm &lt;/ins&gt;is not necessarily an everyday task for a programmer, but uses for sorting are sufficiently commonplace that the expectations for a sorting routine are familiar. This familiarity, however, often brings with it a false sense of knowledge.&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;When programmers are asked what they would test for if they were to implement a sorting routine, the answer most commonly given is that the resulting sequence of elements is sorted, i.e., the elements are in non-descending order. While this is not wrong, it is also not completely correct. When prompted for a more precise condition, many programmers add that the resulting sequence should be the same length as the original. Although correct, this is still insufficient. For example, given the sequence of values &amp;lt;code&amp;gt;[3, 1, 4, 1, 5, 9]&amp;lt;/code&amp;gt;, the sequence &amp;lt;code&amp;gt;[3, 3, 3, 3, 3, 3]&amp;lt;/code&amp;gt; satisfies &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;the stated &lt;/del&gt;postcondition. It also contains an error taken from real production code (fortunately caught before it was released), where a simple slip of a keystroke or momentary lapse of reason led to an elaborate mechanism for populating a whole array with the first element of the passed array.&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;When programmers are asked what they would test for if they were to implement a sorting routine, the answer most commonly given is that the resulting sequence of elements is sorted, i.e., the elements are in non-descending order. While this is not wrong, it is also not completely correct. When prompted for a more precise condition, many programmers add that the resulting sequence should be the same length as the original. Although correct, this is still insufficient. For example, given the sequence of values &amp;lt;code&amp;gt;[3, 1, 4, 1, 5, 9]&amp;lt;/code&amp;gt;, the sequence &amp;lt;code&amp;gt;[3, 3, 3, 3, 3, 3]&amp;lt;/code&amp;gt; satisfies &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;a &lt;/ins&gt;postcondition &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;of being sorted in non-descending order and having the same length as the original sequence&lt;/ins&gt;. It also contains an error taken from real production code (fortunately caught before it was released), where a simple slip of a keystroke or momentary lapse of reason led to an elaborate mechanism for populating a whole array with the first element of the passed array.&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;The full postcondition is that the result is sorted ''and'' that it holds a permutation of the passed values. This appropriately constrains the required behaviour. The fact that the result length is the same as the input length comes out in the wash and doesn't need restating.&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;The full postcondition is that the result is sorted ''and'' that it holds a permutation of the passed values. This appropriately constrains the required behaviour. The fact that the result length is the same as the input length comes out in the wash and doesn't need restating.&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;Even stating the postcondition in the way described is not enough to give you a good test. A good test should be readable. It should be comprehensible and simple enough that you can see readily that it is correct (or not). Unless you already have code lying around for checking that a sequence is sorted and that one sequence contains a permutation of values in another, it is quite likely that the test code will be more complex than the code under test. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Using concrete examples eliminates this accidental complexity and opportunity for accident. For example, the result of sorting &amp;lt;code&amp;gt;[3, 1, 4, 1, 5, 9]&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;[1, 1, 3, 4, 5, 9]&amp;lt;/code&amp;gt;. No other answer will do.&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;Even stating the postcondition in the way described is not enough to give you a good test. A good test should be readable. It should be comprehensible and simple enough that you can see readily that it is correct (or not). Unless you already have code lying around for checking that a sequence is sorted and that one sequence contains a permutation of values in another, it is quite likely that the test code will be more complex than the code under test. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;As Tony Hoare noted:&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;Concrete examples helps to illustrate general behavior in an accessible and unambiguous way. The result of adding an item to an empty collection is not simply that it is not empty, it is that the collection now has a single item. Two or more items qualify as not empty. And also as wrong. The result of adding a row to a table is not simply that the table is one row bigger, it also entails that the row's key can be used to recover the row added. And so on. In specifying behavior, tests should not simply be accurate, they also need to be precise.&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;: There are two ways of constructing a software design: One way is to make it so simple that there are ''obviously'' no deficiencies and the other is to make it so complicated that there are no ''obvious'' deficiencies.&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;Using concrete examples eliminates this accidental complexity and opportunity for accident. For example, the result of sorting &amp;lt;code&amp;gt;[3, 1, 4, 1, 5, 9]&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;[1, 1, 3, 4, 5, 9]&amp;lt;/code&amp;gt;. No other answer will do.&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;Concrete examples helps to illustrate general behavior in an accessible and unambiguous way. The result of adding an item to an empty collection is not simply that it is not empty, it is that the collection now has a single item&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;. And that the single item held is the item added&lt;/ins&gt;. Two or more items qualify as not empty. And also as &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;wrong. A single item of a different value is also &lt;/ins&gt;wrong. The result of adding a row to a table is not simply that the table is one row bigger, it also entails that the row's key can be used to recover the row added. And so on. In specifying behavior, tests should not simply be accurate, they also need to be precise.&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 [[Kevlin Henney]]&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 [[Kevlin Henney]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</description>
			<pubDate>Sun, 05 Jul 2009 18:49:42 GMT</pubDate>			<dc:creator>Kevlin</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Test_Precisely_and_Concretely</comments>		</item>
		<item>
			<title>Kevlin: New page: Although it is important to test for desired, essential behavior rather than incidental behavior of an implementation, this should not be construed or mistaken as an excuse for vague tests...</title>
			<link>http://commons.oreilly.com/wiki/index.php?title=Test_Precisely_and_Concretely&amp;diff=12755&amp;oldid=prev</link>
			<description>&lt;p&gt;New page: Although it is important to test for desired, essential behavior rather than incidental behavior of an implementation, this should not be construed or mistaken as an excuse for vague tests...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Although it is important to test for desired, essential behavior rather than incidental behavior of an implementation, this should not be construed or mistaken as an excuse for vague tests. Tests need to be both accurate ''and'' precise.&lt;br /&gt;
&lt;br /&gt;
Something of a tried and tested (and testing) classic, sorting routines provide an illustrative example. Implementing sorting algorithms is not necessarily an everyday task for a programmer, but uses for sorting are sufficiently commonplace that the expectations for a sorting routine are familiar. This familiarity, however, often brings with it a false sense of knowledge.&lt;br /&gt;
&lt;br /&gt;
When programmers are asked what they would test for if they were to implement a sorting routine, the answer most commonly given is that the resulting sequence of elements is sorted, i.e., the elements are in non-descending order. While this is not wrong, it is also not completely correct. When prompted for a more precise condition, many programmers add that the resulting sequence should be the same length as the original. Although correct, this is still insufficient. For example, given the sequence of values &amp;lt;code&amp;gt;[3, 1, 4, 1, 5, 9]&amp;lt;/code&amp;gt;, the sequence &amp;lt;code&amp;gt;[3, 3, 3, 3, 3, 3]&amp;lt;/code&amp;gt; satisfies the stated postcondition. It also contains an error taken from real production code (fortunately caught before it was released), where a simple slip of a keystroke or momentary lapse of reason led to an elaborate mechanism for populating a whole array with the first element of the passed array.&lt;br /&gt;
&lt;br /&gt;
The full postcondition is that the result is sorted ''and'' that it holds a permutation of the passed values. This appropriately constrains the required behaviour. The fact that the result length is the same as the input length comes out in the wash and doesn't need restating.&lt;br /&gt;
&lt;br /&gt;
Even stating the postcondition in the way described is not enough to give you a good test. A good test should be readable. It should be comprehensible and simple enough that you can see readily that it is correct (or not). Unless you already have code lying around for checking that a sequence is sorted and that one sequence contains a permutation of values in another, it is quite likely that the test code will be more complex than the code under test. Using concrete examples eliminates this accidental complexity and opportunity for accident. For example, the result of sorting &amp;lt;code&amp;gt;[3, 1, 4, 1, 5, 9]&amp;lt;/code&amp;gt; is &amp;lt;code&amp;gt;[1, 1, 3, 4, 5, 9]&amp;lt;/code&amp;gt;. No other answer will do.&lt;br /&gt;
&lt;br /&gt;
Concrete examples helps to illustrate general behavior in an accessible and unambiguous way. The result of adding an item to an empty collection is not simply that it is not empty, it is that the collection now has a single item. Two or more items qualify as not empty. And also as wrong. The result of adding a row to a table is not simply that the table is one row bigger, it also entails that the row's key can be used to recover the row added. And so on. In specifying behavior, tests should not simply be accurate, they also need to be precise.&lt;br /&gt;
&lt;br /&gt;
By [[Kevlin Henney]]&lt;br /&gt;
&lt;br /&gt;
This work is licensed under a [http://creativecommons.org/licenses/by/3.0/us/ Creative Commons Attribution 3] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Back to [[97 Things Every Programmer Should Know]] home page&lt;/div&gt;</description>
			<pubDate>Wed, 22 Oct 2008 13:17:08 GMT</pubDate>			<dc:creator>Kevlin</dc:creator>			<comments>http://commons.oreilly.com/wiki/index.php/Talk:Test_Precisely_and_Concretely</comments>		</item>
	</channel>
</rss>