<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Jose's Blog : Testing</title><link>http://blogs.msdn.com/josealmeida/archive/tags/Testing/default.aspx</link><description>Tags: Testing</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How To: Extend the Network Types for a Visual Studio Load Test</title><link>http://blogs.msdn.com/josealmeida/archive/2008/08/20/how-to-extend-the-network-types-for-a-visual-studio-load-test.aspx</link><pubDate>Wed, 20 Aug 2008 16:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8881219</guid><dc:creator>josealmeida</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/josealmeida/comments/8881219.aspx</comments><wfw:commentRss>http://blogs.msdn.com/josealmeida/commentrss.aspx?PostID=8881219</wfw:commentRss><description>&lt;P&gt;Out-of-the-box Visual Studio allows testers to define a network mix for load tests with the following network profiles:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;LAN&lt;/LI&gt;
&lt;LI&gt;T3 6.0 Mps&lt;/LI&gt;
&lt;LI&gt;T1&lt;/LI&gt;
&lt;LI&gt;Cable/DSL 1.5Mbps&lt;/LI&gt;
&lt;LI&gt;Cable/DSL 768k&lt;/LI&gt;
&lt;LI&gt;Cable/DSL 384k&lt;/LI&gt;
&lt;LI&gt;Dial-up 56k&lt;/LI&gt;
&lt;LI&gt;Dial-up 33.6k&lt;/LI&gt;
&lt;LI&gt;Dial-up 28.8k&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;If we want to add an additional entry, say "Dial-up 128k", we'll have to add a new network profile definition file.&lt;/P&gt;
&lt;P&gt;These files can be found in the following folder:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;C:\Program Files\Microsoft Visual Studio 9.0\Common7\ide\Templates\LoadTest\Networks&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just select an appropriate file (say "Dial-up 56k.network"), copy and rename it (to "Dial-up 128k.network") and edit it's contents accordingly:&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: gray 1px solid; PADDING-RIGHT: 4px; BORDER-TOP: gray 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 8pt; PADDING-BOTTOM: 4px; MARGIN: 20px 0px 10px; OVERFLOW: auto; BORDER-LEFT: gray 1px solid; WIDTH: 97.5%; CURSOR: text; MAX-HEIGHT: 200px; LINE-HEIGHT: 12pt; PADDING-TOP: 4px; BORDER-BOTTOM: gray 1px solid; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BACKGROUND-COLOR: #f4f4f4"&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Network&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="Dial-up 128k"&lt;/SPAN&gt; &lt;SPAN style="COLOR: #ff0000"&gt;BandwidthInKbps&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;="128"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #0000ff"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #800000"&gt;Network&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P&gt;You'll have to close all Visual Studio instances and re-open them so that it can reload all network profiles.&lt;/P&gt;
&lt;P&gt;Related Links:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A class="" href="http://blogs.infosupport.com/marcelv/archive/2005/10/23/1809.aspx" mce_href="http://blogs.infosupport.com/marcelv/archive/2005/10/23/1809.aspx"&gt;Adding Firefox browser to load test you websites in Team System&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8881219" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Testing/default.aspx">Testing</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/How+To/default.aspx">How To</category></item><item><title>Unit testing session</title><link>http://blogs.msdn.com/josealmeida/archive/2004/07/05/173147.aspx</link><pubDate>Mon, 05 Jul 2004 19:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:173147</guid><dc:creator>josealmeida</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/josealmeida/comments/173147.aspx</comments><wfw:commentRss>http://blogs.msdn.com/josealmeida/commentrss.aspx?PostID=173147</wfw:commentRss><description>&lt;P&gt;During TechEd'04 in Amsterdam I attended a Birds Of a Feather session on how to integrate unit testing into the Software Development Life-Cycle. For those who are unfamiliar with the format of these sessions, it's a speaker moderated discussion, where we can ask questions and have them answered and commented by the speaker and other attendees. I enjoyed this session format very much as it's highly interactive.&lt;/P&gt;
&lt;P&gt;This session was moderated by James Newkirk. The audience placed a few questions that led to various discussions on unit testing and the correct way to do them (or not to do them), unit testing techniques and personal experiences both positive and negative when using these techniques.&lt;/P&gt;
&lt;P&gt;Below are the topics discussed during this session and I thought of placing them here, along with some of my personal impressions on the various subjects.&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=1&gt;Testing abstract classes with different implementations&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;How to test a virtual implementation of a class, when different implementations can spawn at any time ?&lt;/P&gt;
&lt;P&gt;James Newkirk was of the opinion that you should abstract the tests when a new implementation appears.&lt;/P&gt;
&lt;P&gt;My opinion on the subject follows along the same lines. If I'm doing TDD, I want to write test code for all my implementation (this is my opinion on testing privates as well, BTW). So, I'm a firm believer in testing the implementation not the contract, because that's where my logic will be. It's also my opinion that I should code my unit tests just like I do my production code. So, when there's the need to do some refactoring in my unit test code, I'll do it. This includes doing an Extract Interface, or Extract Class, or any other abstraction refactoring.&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=2&gt;How much to test / testing privates&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;This is a topic that has always had strong arguments pro and against as was also evident in this session. While James Newkirk's opinion is not to test privates, I'm not so sure we shouldn't. James doesn't like to test the private methods, because it hinders refactoring. But if you don't have a test for a piece of logic, how can you refactor it (this seems like a catch 22 to me) ?&lt;/P&gt;
&lt;P&gt;As I've stated above I'm not so sure we shouldn't test private members. I guess that this depends on how I do TDD. There are two different approaches here. Write code test-first only considering the publicly visible members (or the public interface), or write tests for all your logic and during refactoring, if a given method turns out not to be used by any other class other than the test class, use the Hide Method refactoring. I use this last approach, for two reasons: &lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 1in; DIRECTION: ltr; unicode-bidi: embed" type=a&gt;
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=1&gt;If I'm only coding tests for the public interface, I'll have no idea how much logic I'll be having "under the hood" or beneath the public interface. But typically, as someone pointed out during this discussion, this is were most of the logic will be; 
&lt;LI style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=2&gt;The other reason is that this allows me to code this (soon to be) "internal" logic, using a test-driven approach, which gives me confidence in the implementation and how I refactor it.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;This approach, however, leaves me with a bunch of orphaned test methods, since they can no longer access the methods they should be exercising. This is when I usually refactor the test code as well, replacing method invocation with reflective method discovery and invocation.&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=3&gt;Legacy code w/o tests&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;The scenario is the following. You have a large code-base for which you don't have any unit tests. You'd like to add unit tests, but where do you start ?&lt;/P&gt;
&lt;P&gt;James answered this question in a very pragmatic way IMO. "Don't add unit tests for anything you aren't about to change." He said.&lt;/P&gt;
&lt;P&gt;Well this seems a very sensible decision. He then elaborated on this by stating that it could be done by establishing a virtual "boundary" of unit tests defined by the things about to be changed. Tests can be written against this "boundary" and the changes made on the inside of the boundary.&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=4&gt;How to convince people to code test-first?&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;I see this issue as a very hot topic. Primarily because, I have been trying to convince people to adopt this way of developing. And I know from personal experience that it's hard to find the right arguments. Strangely enough, I've found that direct management (PMs or Dev Leads) are more receptive to the message of TDD than the actual developers.&lt;/P&gt;
&lt;P&gt;James Newkirk stated that developing software "...is not about the individual developer, it's about the team and the continuous maintainability of the code". Someone also pointed out that "blinking lights changing from red to green help a lot!" I couldn't agree more.&lt;/P&gt;
&lt;P&gt;Additionally, James pointed out a "technique" that I've also used with some success, which is to ask someone to test their own code. Most of the times people find it hard to write tests against their own code, because they usually don't write their code to be tested.&lt;/P&gt;
&lt;P&gt;This debate spawned another thread of discussion. If the developers write unit tests, which was usually a big chunk of the work that was done by QA teams (white-box testing), the QA teams must start testing at a different (higher) level.&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=5&gt;Mock Objects&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just like &lt;A href="http://www.benjaminm.net/"&gt;Benjamin&lt;/A&gt; posted, "James described mock objects as the situation where object A interacts with objects B and you need some way of 'switching out' Object B to create a 'dummy response' from the calls of Object A."&lt;/P&gt;
&lt;P&gt;True, but it's necessary to determine why would we want to 'switch out' Object B. I usually 'switch out' object B if it isn't part of my domain code (maybe it's an object belonging to a third-party API). If my Object B is, for instance a DAL component and it uses ADO.NET to connect to the database, I would use (dynamic) mock objects to replace the ADO.NET's data access components in object B using the "Inversion of Control" pattern. It may be somewhat complex, but it promotes decoupling and testability, which rate very high in my trade-off scale, so I usually think it's worth it and end up implementing it.&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=6&gt;Testing against a DB.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Sometimes it's hard to mock out the data access layer components, someone pointed out. This is true and there's usually a tendency to end up testing against the database.&lt;/P&gt;
&lt;P&gt;Actually, James Newkirk says that there are situations where he prefers to test against the database. "When writing unit tests for DAL components use the actual database. When writing unit tests for components that use DAL components, mock out the DAL components." James said.&lt;/P&gt;
&lt;P&gt;I have a different point of view. If the DAL components where written by me, I'd like to test not only the components that use the DAL components, but also the interaction between them. On the other hand, data connectivity components supplied by the underlying API (system or third-party) are not part of my domain code and I can&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;(and probably should) mock them out.&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=7&gt;How long should tests run ?&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;This was an interesting point, as people have very different experiences. Someone said they had test that took 6 hours to complete, others have them built into the build process and run the whole suite nightly for as long as they take. Another delegate's tests took about 2 hours to complete.&lt;/P&gt;
&lt;P&gt;In James' opinion, 1 hour is too long, because tests should provide rapid feedback to the developer and promote a very fast turn around in the development lifecycle. The recommendation that came out of this debate was that in large projects we should separate developer unit tests and run all the tests (all test suites from all developers) during the daily build cycle. Some integration problems will arise only during build, but it's a trade-off.&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=8&gt;Automatic test generation.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Commercial products don't take into account the actual intention of the methods being tested and so usually create 'poor' tests. On the other hand, Visual Studio Team System has a built-in functionality to implement a boiler plate test for any given method.&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-WEIGHT: bold; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle" value=9&gt;How do you unit test GUIs ?&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;In any discussion on unit testing this topic usually comes up. In this session people mentioned some commercial products that they've used with some success, although they couldn't survive for more than a few builds without breaking them. A pretty "standard" response to this issue is to use the Model View Controller design pattern to separate presentation and presentation control logic and eventually test them individually.&lt;/P&gt;
&lt;P&gt;The problem is that when we're coding unit tests against an API, the interface is programmatic, whilst when we are coding unit tests for a GUI, the interface is visual and designed for human and not machine interaction.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx"&gt;I've used NUnitForms&lt;/A&gt; and NUnitASP with some success to get around this situation and exercise the visual elements of the GUI individually. The main drawback with both of these extensions to NUnit is the relatively small number of controls supported (granted that they are the most used).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, a few other questions and discussions came up, but were marginal to the previous ones that were the main thread of the session.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=173147" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Unit Testing User Interfaces (Updated!)</title><link>http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx</link><pubDate>Tue, 15 Jun 2004 23:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:156101</guid><dc:creator>josealmeida</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/josealmeida/comments/156101.aspx</comments><wfw:commentRss>http://blogs.msdn.com/josealmeida/commentrss.aspx?PostID=156101</wfw:commentRss><description>Usually one of the major difficulties a developer faces when writing unit tests is how to write test code for User Interfaces. This is particularly important when we're doing Test-Driven Development....(&lt;a href="http://blogs.msdn.com/josealmeida/archive/2004/06/15/UnitTestingUserInterfaces.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=156101" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Agile/default.aspx">Agile</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Testing/default.aspx">Testing</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Post+Updates/default.aspx">Post Updates</category></item><item><title>Loading .config files in NUnit</title><link>http://blogs.msdn.com/josealmeida/archive/2004/05/31/loading-config-files-in-nunit.aspx</link><pubDate>Mon, 31 May 2004 23:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:144930</guid><dc:creator>josealmeida</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/josealmeida/comments/144930.aspx</comments><wfw:commentRss>http://blogs.msdn.com/josealmeida/commentrss.aspx?PostID=144930</wfw:commentRss><description>&lt;P&gt;Last week I gave a presentation at &lt;a title="Microsoft" href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt; DevDays 2004 in Lisbon on Test-Driven Development. A day later I got this interesting question:&lt;/P&gt;
&lt;P&gt;"(...) if I'm testing a DLL assembly that uses a .config file to read in data, when I run the tests, NUnit loads it's own .config file and all my tests fail. How can I solve this ?"&lt;/P&gt;
&lt;P&gt;I also had this same problem a while back. There are two separate answers to this question as far as I could tell:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;If we're using the NUnit GUI than it's just a question to specify which .config file to load (Project -&amp;gt; Edit)&lt;/LI&gt;
&lt;LI&gt;If we're running NUnit from the console, copy the config file to the directory where the test assembly is located (tipically bin\Debug) and rename the config file to &amp;lt;test assembly&amp;gt;.config (ex: UniTests.dll.config)&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;This will cause NUnit to load the required .config file.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=144930" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Testing/default.aspx">Testing</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/How+To/default.aspx">How To</category></item><item><title>Testable code</title><link>http://blogs.msdn.com/josealmeida/archive/2004/04/27/120968.aspx</link><pubDate>Tue, 27 Apr 2004 19:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:120968</guid><dc:creator>josealmeida</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/josealmeida/comments/120968.aspx</comments><wfw:commentRss>http://blogs.msdn.com/josealmeida/commentrss.aspx?PostID=120968</wfw:commentRss><description>&lt;P&gt;Previously I mentioned that one of the most important benefits I get from using TDD is that it drives me to write more testable code. I've been thinking quite a lot about this, and another recent &lt;A href="http://blogs.msdn.com/chappell/archive/2004/04/21/117670.aspx"&gt;post&lt;/A&gt; from &lt;A href="http://blogs.msdn.com/chappell/"&gt;Chris Dickens&lt;/A&gt; made we even more aware of the importance behind writing testable code.&lt;/P&gt;
&lt;P&gt;Chris states:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;"As you might expect, before we can start serious development we have to write specs. Those aren't my job (that's what &lt;A href="http://www.microsoft.com/college/fulltime/pm.asp"&gt;Program Managers&lt;/A&gt; do) but developers and testers are actively involved in critiquing the specs. Technically my purpose in those meetings is to flag any design issues that would make the product untestable, but in reality I'm there to provide my input on what the product should do."&lt;/P&gt;
&lt;P&gt;I've found (the hard way) that trying to test code that wasn't written with testing in mind, is extremely hard, especially when you find tightly-coupled code.&lt;/P&gt;
&lt;P&gt;TDD promotes decoupling and this, by itself, is very helpful in producing testable code, because there's some way to plug into the production logic you want to test. If the code you're testing depends on other parts of the system you can find yourself writing a huge amount of code into the setup methods of the unit tests. This, unfortunately, introduces a high degree of coupling into the testing logic, particularly if the code you're dependant on belongs to another domain (i.e. it's an external system)&lt;/P&gt;
&lt;P&gt;Using&amp;nbsp;mock objects can help us develop loosely-coupled unit tests.&amp;nbsp;Considering this, some questions seem to arise almost instantly... "When should mock objects be used?", "Is it recommended to use mock objects to represent every external system that our production code interacts with?", etc.&lt;/P&gt;
&lt;P&gt;Here's a definition of&amp;nbsp;a &lt;A href="http://c2.com/cgi/wiki?MockObject"&gt;Mock Object&lt;/A&gt;:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;is easily created 
&lt;LI&gt;is easily set up 
&lt;LI&gt;is quick 
&lt;LI&gt;is deterministic 
&lt;LI&gt;has easily caused behaviour 
&lt;LI&gt;has no direct user interface 
&lt;LI&gt;is directly queriable &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;From the above definition, it's possible to identify a couple of situations where using mock objects can be valuable in coding&amp;nbsp;unit tests: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the real object doesn't yet exist 
&lt;LI&gt;the real object is difficult to setup 
&lt;LI&gt;the real object is slow (if it takes too long to run the tests, you might feel discouraged to run them) 
&lt;LI&gt;the real object produces unpredictable results which may cause the test to behave in a nondeterministic way; 
&lt;LI&gt;the real object is a user interface 
&lt;LI&gt;the test needs to ask the real object how it was used (for instance, the test might need to verify if an event was raised and caught correctly)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Developing unit tests with mock objects, improves domain code by preserving encapsulation, reducing global dependencies, and clarifying the interactions between classes [&lt;A href="http://www.connextra.com/aboutUs/mockobjects.pdf"&gt;Mackinnon, 2000&lt;/A&gt;].&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=120968" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Agile/default.aspx">Agile</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Testing/default.aspx">Testing</category></item><item><title>TDD Adoption Numbers</title><link>http://blogs.msdn.com/josealmeida/archive/2004/04/16/114483.aspx</link><pubDate>Fri, 16 Apr 2004 12:19:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:114483</guid><dc:creator>josealmeida</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/josealmeida/comments/114483.aspx</comments><wfw:commentRss>http://blogs.msdn.com/josealmeida/commentrss.aspx?PostID=114483</wfw:commentRss><description>&lt;P&gt;Matt Hawley &lt;A href="http://weblogs.asp.net/mhawley/archive/2004/04/15/114005.aspx"&gt;posted&lt;/A&gt; a few numbers in order to justify/support the adoption of TDD.&lt;/P&gt;
&lt;P&gt;I've found an interesting &lt;A href="http://www.ipd.uka.de/~muellerm/publications/edser03.pdf"&gt;research paper &lt;/A&gt;on the subject, from Matthias Müller and Frank Padberg from the &lt;A href="http://www.uni-karlsruhe.de/Uni/"&gt;Karlsruhe University&lt;/A&gt; in Germany.&lt;/P&gt;
&lt;P&gt;Some of my personal views on the subject are:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;I do find there's a slight overhead to developing Test-First. However all developers unit-test their code, to one degree or another. All developers write some form of test code. I believe the overhead comes, not from writing test code, but from using a testing framework. 
&lt;LI&gt;IMO one of the greatest benefits I've experienced by coding test-first is that the code I write is testable (i.e. If someone else needs to write/extend test-code,&amp;nbsp;for instance to&amp;nbsp;test&amp;nbsp;some wierd situation, it can easily be done); 
&lt;LI&gt;Coding flows with much more confidence (more immediate feedback on what's wrong);&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I do believe that TDD is a very helpful practice and from my experience, together with other practices like Refactoring,&amp;nbsp;I do believe that it helps to write better code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=114483" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Development/default.aspx">Development</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Agile/default.aspx">Agile</category><category domain="http://blogs.msdn.com/josealmeida/archive/tags/Testing/default.aspx">Testing</category></item></channel></rss>