<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tore Vestues blogs &#187; TDD</title>
	<atom:link href="http://tore.vestues.no/category/tdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://tore.vestues.no</link>
	<description>On a quest for the silver bullet..</description>
	<lastBuildDate>Sun, 19 Jun 2011 19:34:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unit tests should not test software</title>
		<link>http://tore.vestues.no/2009/03/20/unit-tests-should-not-test-software/</link>
		<comments>http://tore.vestues.no/2009/03/20/unit-tests-should-not-test-software/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 05:32:23 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Practices]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/2009/03/20/unit-tests-should-not-test-software/</guid>
		<description><![CDATA[Register your claim
When I refactor or make changes to code I need somehow to verify that the changes do not break anything. I want to do it with unit tests. Unit tests are my safety net. My philosophy on unit testing is something like, if you do not want me to change some of your [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Register your claim</strong><br />
When I refactor or make changes to code I need somehow to verify that the changes do not break anything. I want to do it with unit tests. Unit tests are my safety net. My philosophy on unit testing is something like, if you do not want me to change some of your functionality then &#8220;register your claim&#8221; on that functionality as a unit test. </p>
<p><strong>Unit tests specify</strong><br />
There is a lot of functionality (or business logic) that is accidental, meaning that it is not really necessary and it might even be plain wrong, a bug. It happens, a lot. It is hard to know if a piece of code is accidental or not if you do not have a way to express it. A unit test is a great way to express your intent and your &#8220;real&#8221; functionality. For me, unit tests are specifications. They specify the intended functionality. This is explicit functionality. I love explicit functionality. In fact I love almost anything explicit when it comes to code. I want to read loud and clear what the intentions are. The opposite of explicit functionality is of course implicit functionality. This is the functionality that resides in the code without anything or one to claim its importance. Implicit functionality might always be accidental, and that is why it is so hard to work with that kind of functionality. You do not know if it&#8217;s supposed to be there. </p>
<p><strong>Unit tests verify</strong><br />
If all important functionality is ensured with unit tests, you have your safety net. The unit tests verify what you specified. Then refactoring is a dream. Keeping the codebase neat, up to date and clean is easy. To be able to nurture your codebase, through refactoring, you will need this safety net. It verifies your intentions and ignores all unnecessary code. </p>
<p><strong>Unit tests do not test software</strong><br />
This way unit tests ensures that the intended functionality in your classes stays there, and makes it easier to refactor. But it does not check if your system work. It does not verify that you have put it all together the right way. It does not check if everything goes right in the databases, on files or in the user interface. Partly integration tests will do this job for you, and partly manual testing. </p>
<p><strong>Abstractions through OO</strong><br />
When I talk about unit tests, I consider my units to be classes. I also want to stress the point of knowing where to put your logic. Responsibilities should be placed where it belongs, in the right concepts (on the right classes). This is the fundament of object orientation, expressed elegantly through domain driven design. The concepts are the classes. Thus it is very important to verify the logic where it belongs, on the classes. And why should we use classes and separate logic? There are mighty reasons for this, but for now let me just say: to avoid cognitive overload. </p>
<p><strong>You need all types of tests</strong><br />
So, unit tests are there to specify the behavior of the systems concepts (think DDD). This is imperative to be able to refactor the core of your system. But as I&#8217;ve said, this is far from enough to test your system. I find integration tests best for testing your software. Tests that are more like acceptance tests, checking a complete path of calls from top to bottom (and yes, I often include the database in these tests). In addition there are things you will not be able to test automatically (that easily). How does the gui look and feel? You need someone to test that too. </p>
<p>To conclude, you need a whole lot of unit tests to lock down functionality. You need integration tests to test your software, and you need people to test gui and other stuff that isn&#8217;t feasible to test any other way. And my opinion is that <i>you</i> should do all this before you send it to QA. </p>
<p>-Tore Vestues</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2009/03/20/unit-tests-should-not-test-software/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test-Driven Development</title>
		<link>http://tore.vestues.no/2007/09/15/test-driven-development/</link>
		<comments>http://tore.vestues.no/2007/09/15/test-driven-development/#comments</comments>
		<pubDate>Sat, 15 Sep 2007 11:44:57 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://tore_.vestues.no/2007/09/15/test-driven-development/</guid>
		<description><![CDATA[I&#8217;ve been writing unit tests for quite a while now (this practice seem quite common all over now). In addition, I&#8217;ve been very interested in TDD over the last couple of years. This month I wanted to get a step further, so TDD has been my main focus (see my post &#8220;Apply the knowledge&#8221;). This [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing unit tests for quite a while now (this practice seem quite common all over now). In addition, I&#8217;ve been very interested in TDD over the last couple of years. This month I wanted to get a step further, so TDD has been my main focus (see my post &#8220;Apply the knowledge&#8221;). This extra attention on TDD has given me some new and exiting insites to how and why, so here&#8217;s my new found thoughts, together with my general view on TDD.</p>
<p><strong>Design is the key</strong></p>
<p>I feel stronger and stronger that TDD is all about design, especially if you take the need-driven/mockist-approach (see article reference below). Your system will look different if you create it test first. Apart from the fact that it will be easy to test (never running into detestable objects), TDD-developed systems tend to have lower coupling, which in turn has a positive effect on a systems flexibility, which again is nessecary for applying refactoring.. I could go on.</p>
<p class="vspace">The article, <a target="_blank" href="http://www.mockobjects.com/files/mockrolesnotobjects.pdf">&#8220;Mock roles, not objects&#8221;</a>, describes TDD as a design prosess in an exellent way. When I first read it, it really opened my eyes on how to design flexible systems with TDD.</p>
<p class="vspace"><strong>Verification</strong></p>
<p>In his article <a target="_blank" href="http://www.martinfowler.com/articles/mocksArentStubs.html">&#8220;Mocks aren&#8217;t stubs&#8221;</a>, Martin Fowler writes about the difference in using mock objects or not. He finds that (among other things) when using mocks you use behavior verification, while others use state verification.</p>
<p class="vspace">Fowler argues also that mockist tests couples the tests to implementation since it uses behavior verification. Allthough I do not totally agree on his views on this issue, here he has a good point. The main problem with behavior verification is that the test and the SUT (Subject under test) is tightly coupled together. Coupling between testclass and SUT is no problem when they are coupled together on the expected external behaviour, because if you want to change that, you want to change the test first. But it is a problem if a change that does not change the external contract, will break tests. This means our code is less flexible, and it will lead to more work for every internal change, like a refactoring.</p>
<p class="vspace">This does not mean that I&#8217;m giving up mocking (I still love the way it drives my design), and it does not mean that I will mock less. So, what do I do?</p>
<p class="vspace">First, I verify external state, if there are any, like I&#8217;ve always done in addition to verifying behavior.</p>
<p class="vspace">Second, some behavior can actually be regarded as a part of the public contract. For instance if an objects is supposed to post three messages to a log-queue, if it receives three notifications, this is behavior, and it can be regarded as public, at least for test purposes. This kind of behavior can easily be tested using mock objects.</p>
<p class="vspace">Third, for private behavior, I try to be as loose as possible in my expectations. I often use Expect.Any() or <span class="wikiword">Expect.AtLeastOnce</span>() instead of Expect.Once() or Expect.Never(). In these cases we&#8217;re not really that interested in the behavior, we&#8217;re more interested in controlling the supply of objects to the SUT.</p>
<p class="vspace"><strong>Your tests are your documentation</strong></p>
<p class="vspace">I&#8217;ve been reading alot about how your tests should be the key to understanding your systems behavior. Until now, I have thought that reading actual test code is the key. In one sense it is, if you read the test code, you understand in detail what that test tests. But honestly, no matter how much refactoring you do to make your tests understandable, looking at test code doesn&#8217;t really give you a quick overview of what is expected, as a whole, of a class.</p>
<p class="vspace">But then I suddenly realized that the key is in the test names (method names), not in the test code.  Let the test method names describe the expected behaviour of the SUT, reading those names should be sufficient to get an understanding of the obejcts responsibilites and limitations. This means that all requirements of a class must not only be tested by a test class, it also has to be explained explicitly in the test method&#8217;s names.</p>
<p class="vspace">For links on TDD, go to the links page.</p>
<p class="vspace">Tore Vestues</p>
<p class="vspace">&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2007/09/15/test-driven-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

