<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>TDD &amp; XP</title><link>http://blogs.clearscreen.com/ragc/category/19.aspx</link><description>Test Driven Development and eXtreme Programing</description><managingEditor>Raúl Alarcón García-Cuevas</managingEditor><dc:language>es-ES</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Raúl Alarcón García-Cuevas</dc:creator><title>NHibernate, gathering the Java experience saving objects to Relation Databases</title><link>http://blogs.clearscreen.com/ragc/archive/2005/01/31/884.aspx</link><pubDate>Mon, 31 Jan 2005 11:22:00 GMT</pubDate><guid>http://blogs.clearscreen.com/ragc/archive/2005/01/31/884.aspx</guid><wfw:comment>http://blogs.clearscreen.com/ragc/comments/884.aspx</wfw:comment><comments>http://blogs.clearscreen.com/ragc/archive/2005/01/31/884.aspx#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://blogs.clearscreen.com/ragc/comments/commentRss/884.aspx</wfw:commentRss><trackback:ping>http://blogs.clearscreen.com/ragc/services/trackbacks/884.aspx</trackback:ping><description>&lt;p&gt;January is ending, to avoid pass this month without writing to my blog I have decided write about &lt;strong&gt;NHibernate&lt;/strong&gt;, available from &lt;strong&gt;&lt;a href="http://nhibernate.sourceforge.net/"&gt;http://nhibernate.sourceforge.net/&lt;/a&gt;&lt;/strong&gt;&lt;strong&gt;.&lt;/strong&gt; This open source project, from SourceForge, is a port from &lt;a href="http://hibernate.org/"&gt;Hibernate&lt;/a&gt;, a mature java relational persistence tool currently in the 2.0 version.&lt;/p&gt;
&lt;p&gt;I don't have tested this tool, but reading the &lt;strong&gt;&lt;a href="http://nhibernate.sourceforge.net/quickstart.html"&gt;QuickStart&lt;/a&gt;&lt;/strong&gt; guide I feel that it could be a very useful approach to save objects to relational databases. You can start designing the objects or designing the database, NHibernate establish a bridge to connect both. Furthermore, you can change the back-end database server without modifying the objects in your code, anyway you must extend the Dialect name space if the new database manager is not supported. &lt;/p&gt;
&lt;p&gt;Currently, the release (0.6.0.0) is been developed, I expect so much from the first version. Keep your eyes on this project, smell like this will be helpful in the future development process.&lt;/p&gt;&lt;img src ="http://blogs.clearscreen.com/ragc/aggbug/884.aspx" width = "1" height = "1" /&gt;</description><body xmlns="http://www.w3.org/1999/xhtml"><p>January is ending, to avoid pass this month without writing to my blog I have decided write about <strong>NHibernate</strong>, available from <strong><a href="http://nhibernate.sourceforge.net/">http://nhibernate.sourceforge.net/</a></strong><strong>.</strong> This open source project, from SourceForge, is a port from <a href="http://hibernate.org/">Hibernate</a>, a mature java relational persistence tool currently in the 2.0 version.</p>
<p>I don't have tested this tool, but reading the <strong><a href="http://nhibernate.sourceforge.net/quickstart.html">QuickStart</a></strong> guide I feel that it could be a very useful approach to save objects to relational databases. You can start designing the objects or designing the database, NHibernate establish a bridge to connect both. Furthermore, you can change the back-end database server without modifying the objects in your code, anyway you must extend the Dialect name space if the new database manager is not supported. </p>
<p>Currently, the release (0.6.0.0) is been developed, I expect so much from the first version. Keep your eyes on this project, smell like this will be helpful in the future development process.</p><img src ="http://blogs.clearscreen.com/ragc/aggbug/884.aspx" width = "1" height = "1" /></body></item><item><dc:creator>Raúl Alarcón García-Cuevas</dc:creator><title>Testing with Mock Objects and C#</title><link>http://blogs.clearscreen.com/ragc/archive/2004/08/31/395.aspx</link><pubDate>Tue, 31 Aug 2004 09:16:00 GMT</pubDate><guid>http://blogs.clearscreen.com/ragc/archive/2004/08/31/395.aspx</guid><wfw:comment>http://blogs.clearscreen.com/ragc/comments/395.aspx</wfw:comment><comments>http://blogs.clearscreen.com/ragc/archive/2004/08/31/395.aspx#Feedback</comments><slash:comments>61</slash:comments><wfw:commentRss>http://blogs.clearscreen.com/ragc/comments/commentRss/395.aspx</wfw:commentRss><trackback:ping>http://blogs.clearscreen.com/ragc/services/trackbacks/395.aspx</trackback:ping><description>&lt;P&gt;Mock objects present an alternative way to make tests for our classes simplifying the testing process and making possible test specific behaviour of our classes when this behaviour relies in other complex classes or subsystems.When we are making unit tests and our class uses other complex classes or subsystems, we could find the following problems:&lt;/P&gt;
&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;a) The preparation for the test is hard because of the environment required by the collaborative classes (or subsystems) is complex.&amp;nbsp;In example, think in classes that rely in other classes to retrieve information from the database. To test this kind of classes we need configure a basic data set in the database that represents a snapshot with the concrete context for our testing purposes.&lt;/P&gt;
&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;b) We can&amp;#8217;t use the subsystem classes because of they had not been developed yet. In early stages of development process, different teams are owners of different parts or subsystems in the global solution. Mock objects let us the opportunity of advance in the development process despites other required subsystem is not available yet.&lt;/P&gt;
&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;c) The behaviour that we are trying to test depends on a remotely situation happened in the subsystem. In example, to check if the exception handling when the subsystem rises a technical error, we need to produce&amp;nbsp;the technical error in the real subsystem. This would be impossible if we are dealing with a real subsystem in a production environment.&lt;/P&gt;
&lt;P&gt;In all of these situations, we can consider substitute the subsystem with a &amp;#8220;mock object&amp;#8221;&amp;nbsp; that simulate the expected behaviour required to check our system, we get a really big independency from the subsystem&amp;nbsp; enabling us make our tests more simple, more effective and quickly.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;To illustrate the mock object concept, look at this dummy C# example:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;We are going to use an existing weather web service to make a little class witch get the weather conditions for the current day. Within the web service methods there is the following:&lt;/P&gt;
&lt;P&gt;- &lt;EM&gt;GetWeatherConditions(string callerName)&lt;/EM&gt;, returns an integer value representing the weather condition (0 &amp;#8211; Sunny, 1 &amp;#8211; Cloudy, 2 &amp;#8211; Rainy&amp;#8230; )&lt;/P&gt;
&lt;P&gt;We have developed the &amp;#8220;CurrentWeather&amp;#8221; class. The constructor will be like:&lt;SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;BR&gt;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/SPAN&gt; CurrentWeather()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;&amp;nbsp;_webServiceUrl &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; ConfigurationSettings.AppSettings[&lt;SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Url"&lt;/SPAN&gt;];&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;}&lt;BR&gt;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;The class has the &amp;#8220;GetWeather()&amp;#8221; method witch connect to the web service, get the weather conditions and save it in suitable private variables. The method always use the string &amp;#8220;CurrentWeatherClass&amp;#8221; as caller name to make the &amp;#8220;GetWeatherConditions&amp;#8221; call. We assume that the method has been tested before.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;We want in our class a new property to get an image name representing the current weather conditions. To develop this method we are going to start with the test:&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;BR&gt;&amp;nbsp;[Test]&lt;BR&gt;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/SPAN&gt; GetWeaderConditionsPictureTest()&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;CurrentWeather todayWeather &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/SPAN&gt; CurrentWather();&lt;BR&gt;&amp;nbsp;&amp;nbsp;todayWeather.GetWeather(); &lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/SPAN&gt; pictureName &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; todayWeather.Picture;&lt;BR&gt;&amp;nbsp;&amp;nbsp;Assert.IsTrue(pictureName.Length &amp;gt; 0);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//We need check if the Picture really fits &lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//the weather condition&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;Assert.Fails();&lt;BR&gt;&amp;nbsp;}&lt;BR&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;In the test, we need check if the picture really fits with the weather conditions retrieved from the web service. In this case, if we use the real subsystem we fall in the following inconveniences:&lt;/P&gt;
&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;a) The picture name that the property &amp;#8220;Picture&amp;#8221; return depends on the real weather, we doesn&amp;#8217;t know the weather before the test runs, therefore, we can&amp;#8217;t make the correct assertion.&lt;BR&gt;b) If we don&amp;#8217;t have a valid connection to the weather web service, the test will fails always.&lt;/P&gt;
&lt;P&gt;To avoid it, we can make a Mock Object that represents the web service; in that case we can make another .NET web service with the same signature as the real web service. In the &amp;#8220;GetWeatherConditions&amp;#8221; method we put logic helping us to make possible the testing:&lt;SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;BR&gt;&amp;nbsp;[WebMethod]&lt;BR&gt;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/SPAN&gt; GetWeatherConditions(&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/SPAN&gt; callerName)&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/SPAN&gt; result;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;switch&lt;/SPAN&gt;(callerName)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;case&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"TestingSunny"&lt;/SPAN&gt;: &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; 0;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;break&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;case&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"TestingCloudy"&lt;/SPAN&gt;:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; 1;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;break&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;case&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"TestingRainy"&lt;/SPAN&gt;:&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;result &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; 2;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;break&lt;/SPAN&gt;;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;...&lt;BR&gt;&amp;nbsp;&amp;nbsp;}&lt;BR&gt;&amp;nbsp;}&lt;BR&gt;&lt;/SPAN&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;After we have the mock-object ready, we must refactor the &amp;#8220;CurrentWeather&amp;#8221; class to make possible use it from tests, in that case we overload the constructor to provide a way to specify the web service URL to be used, as well as the caller name, the new constructor looks like:&lt;SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;BR&gt;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/SPAN&gt; CurrentWeather(&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/SPAN&gt; callerName, &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/SPAN&gt; serviceUrl): &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;base&lt;/SPAN&gt;()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;&amp;nbsp;_webServiceUrl &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; serviceUrl;&lt;BR&gt;&amp;nbsp;_callerName &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; callerName;&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;}&lt;BR&gt;&lt;/SPAN&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The unique change required in the original constructor is to put the default caller name:&lt;SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;BR&gt;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/SPAN&gt; CurrentWeather()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;&amp;nbsp;&amp;nbsp;_webServiceUrl &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; ConfigurationSettings.AppSettings[&lt;SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"Url"&lt;/SPAN&gt;];&lt;BR&gt;&amp;nbsp;_callerName &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; &amp;#8220;CurrentWeatherClass&amp;#8221;;&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;}&lt;BR&gt;&lt;/SPAN&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Now we refactor the &amp;#8220;GetWeather&amp;#8221; method to pass the private variable with the caller name:&lt;SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;BR&gt;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/SPAN&gt; GetWeather()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;&amp;nbsp;WeatherWebService service &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/SPAN&gt; WeatherWebService();&lt;BR&gt;&amp;nbsp;service.Url &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; _webServiceUrl;&lt;BR&gt;&amp;nbsp;_currentWeather &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; service.GetCurrentWeather(_callerName);&lt;BR&gt;&amp;nbsp;...&lt;BR&gt;}&lt;BR&gt;&lt;/SPAN&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;At this point, we can make the required test to check the &amp;#8220;Picture&amp;#8221; property:&lt;SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;BR&gt;&amp;nbsp;[Test]&lt;BR&gt;&amp;nbsp;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;void&lt;/SPAN&gt; GetWeaderConditionsPictureTest()&lt;BR&gt;&amp;nbsp;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;CurrentWeather todayWeather;&lt;BR&gt;&lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/SPAN&gt; pictureName;&lt;BR&gt;&lt;BR&gt;todayWeather &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/SPAN&gt; CurrentWather(&amp;#8220;TestingSunny&amp;#8221;, @&amp;#8220;http:&lt;SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//localhost/WeatherMock&amp;#8221;);&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;todayWeather.GetWeather(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;Assert.AreEquals(&amp;#8220;Sunny.jpg&amp;#8221;, todayWeather.Picture);&lt;BR&gt;&lt;BR&gt;todayWeather &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/SPAN&gt; CurrentWather(&amp;#8220;TestingCloudy&amp;#8221;, @&amp;#8220;http:&lt;SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//localhost/WeatherMock&amp;#8221;);&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;todayWeather.GetWeather(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;Assert.AreEquals(&amp;#8220;Cloudy.jpg&amp;#8221;, todayWeather.Picture);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;BR&gt;todayWeather &lt;SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/SPAN&gt; &lt;SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/SPAN&gt; CurrentWather(&amp;#8220;TestingRainy&amp;#8221;, @&amp;#8220;http:&lt;SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;//localhost/WeatherMock&amp;#8221;);&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;todayWeather.GetWeather(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;Assert.AreEquals(&amp;#8220;Rainy.jpg&amp;#8221;, todayWeather.Picture);&lt;BR&gt;&amp;nbsp;}&lt;BR&gt;&lt;/SPAN&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;And that&amp;#8217;s all... well, the &amp;#8220;GetWeatherConditionsPictureTest&amp;#8221; smells like if needs a refactoring ;)&lt;/P&gt;
&lt;P&gt;In summary, the mock objects provide us a way to test classes that uses complex subsystems. Introduce mock objects in our solution cause a little extra-coding tasks, refactoring the class to be tested and implementing the mock-object logic, anyway, the extra-coding tasks provide more flexibility in the class to be tested making it better.&lt;/P&gt;
&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;There are a lot of alternatives to implement mock objects, for further information checks these URLs:&lt;BR&gt;&lt;A href="http://www.pragmaticprogrammer.com/starter_kit/ut/mockobjects.pdf" target=blank&gt;http://www.pragmaticprogrammer.com/starter_kit/ut/mockobjects.pdf&lt;/A&gt;&lt;BR&gt;&lt;A href="http://www-106.ibm.com/developerworks/library/j-mocktest.html" target=blank&gt;http://www-106.ibm.com/developerworks/library/j-mocktest.html&lt;/A&gt;&lt;BR&gt;&lt;A href="http://c2.com/cgi/wiki?MockObject" target=blank&gt;http://c2.com/cgi/wiki?MockObject&lt;/A&gt;&lt;/P&gt;&lt;img src ="http://blogs.clearscreen.com/ragc/aggbug/395.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Raúl Alarcón García-Cuevas</dc:creator><title>An introduction to TDD (Test Driven Development)</title><link>http://blogs.clearscreen.com/ragc/archive/2004/05/10/189.aspx</link><pubDate>Mon, 10 May 2004 19:24:00 GMT</pubDate><guid>http://blogs.clearscreen.com/ragc/archive/2004/05/10/189.aspx</guid><wfw:comment>http://blogs.clearscreen.com/ragc/comments/189.aspx</wfw:comment><comments>http://blogs.clearscreen.com/ragc/archive/2004/05/10/189.aspx#Feedback</comments><slash:comments>11</slash:comments><wfw:commentRss>http://blogs.clearscreen.com/ragc/comments/commentRss/189.aspx</wfw:commentRss><trackback:ping>http://blogs.clearscreen.com/ragc/services/trackbacks/189.aspx</trackback:ping><description>&lt;P&gt;Here is a very useful&amp;nbsp;article to intruduce you in TDD world, it covers all first questions abount unit testing and how to integrate it in your develop lifetime. The article show fantasticaly how to use NUnit as unit testing tool integrated with C#.&lt;/P&gt;
&lt;P&gt;&lt;A href=http://msdn.microsoft.com/msdnmag/issues/04/04/ExtremeProgramming/ target="_blank"&gt;http://msdn.microsoft.com/msdnmag/issues/04/04/ExtremeProgramming/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;After you have read the article... think about the following questions:&lt;/P&gt;
&lt;P&gt;Are private methods requiered to be unit-tested?&lt;BR&gt;If they are... how you can do it?&lt;/P&gt;&lt;img src ="http://blogs.clearscreen.com/ragc/aggbug/189.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>