<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/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Unit Testing</title>
        <link>http://inphoteck.com/category/19.aspx</link>
        <description>Betcha can't guess what this category is about..</description>
        <language>en-US</language>
        <copyright>Desirea Herrera</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <item>
            <title>Inversion of Control</title>
            <link>http://inphoteck.com/archive/2009/07/26/inversion-of-control.aspx</link>
            <description>&lt;p&gt;While I was reading The Art of Unit Testing by Roy Osherove, I found references to topics that required more investigation. Inversion of Control or IoC was one of them. I vaguely remember reading about it somewhere but being a tech trainer of way too many technologies, and now a lab developer (basically quality assurance checking &amp;amp; screnshotting of MOC labs &amp;amp; labs from other companies),  I've let some topics slide away in favor of stuff related to my job. It's part of the reason I started writing this blog, to hone my skillsets. And now, on to Inversion of Control:&lt;/p&gt;
&lt;p&gt;Inversion of Control is based on the idea of flow control. When you start programming, you learn to write code in classes and methods that control the flow of the program. Your code calls methods that do something and answer back to your code. In Inversion of Control, your central classes wait for the phone call that tells them things they need to know to perform their own activities. &lt;/p&gt;
&lt;p&gt;The &lt;a href="http://en.wikipedia.org/wiki/Inversion_of_control"&gt;example onWikipedia &lt;/a&gt;shows a serverFacade class that initially takes an object parameter to its respondToRequest method. The object is a request for data. The respondToRequest method then uses a DAO (Data Access Object) to get data via it's getData method and convert the data via the aspect's convertData method after using the businesslayer object to test if that object is valid. Based on the first implementation, the serverFacade object is coupled to the DAO object. In the lab of OOP, coupling is discourage.  Since the serverFacade shouldn't know anything about how to convert data, or what to return if the data conversion fails (it is only a facade after all), the second implementation moves all the data conversion and return decisions to the DAO class. This in effect, decouples the two classes.&lt;/p&gt;
&lt;p&gt;In Martin Fowler's article &lt;a href="http://martinfowler.com/articles/injection.htm"&gt;Inversion of Control Containers and the Dependency Injection pattern&lt;/a&gt;, he uses a simple class that splits out finding all movies to a finder class. Problems arise when his friends want that functionality for their programs. They might want to store movies in a different format or in a database. An interface or abstract class solves this by allowing the new developer to create a new class to pass to the MovieLister class that can find all of the movies in their own way via their own implementation. &lt;/p&gt;
&lt;p&gt;The key points to both of these examples is that :&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;The classes need to have very specific goals. If an activity doesn't correspond to the method or class, it needs to be moved out. &lt;/li&gt;
    &lt;li&gt;In order to allow for different external dependencies like how the movies are stored and retrieved, create an interface or abstract class. (This idea makes your program easier to fit different situations as needed.) &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Based on Fowler's explanation, what we're really talking about is setting up "plugins" for our software. Essentially you now have the ability to plugin any external movie storage into his MovieLister class. Data storage is only one of the types of external or outside dependencies your software could come across. It could also rely on network availability, configurations as well as configuration files or data stored on a network, or outside services. &lt;/p&gt;
&lt;p&gt;Fowler asserts that Inversion of Control is a common characteristic of a framework. In &lt;font face="Arial"&gt;&lt;a href="http://martinfowler.com/bliki/InversionOfControl.html"&gt;Inversion of Control&lt;/a&gt; he says:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font size="2"&gt;"A framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points."&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Fowler also thinks Inversion of Control Containers is too generic and renames this to Dependency Injection and further discusses the Server Locator pattern. I highly suggest you read his full article.  &lt;/p&gt;
&lt;p&gt;Going back to the Wikipedia article, it mentiosn that Inversion of Control is also known as the Hollywood Principle. Basically is the ""Don't call us, we'll call you." concept. IoC takes the integration and configuration of the system out of the application, and performs dependency injection.  &lt;/p&gt;
&lt;p&gt;Further Reading:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.codeproject.com/KB/aspnet/IOCDI.aspx"&gt;Design pattern – Inversion of control and Dependency injection &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.devx.com/Java/Article/27583"&gt;Design Better Software with the Inversion of Control Pattern&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/cc707904.aspx"&gt;Inversion of Control Pattern&lt;/a&gt;&lt;/p&gt;

&lt;img src="http://inphoteck.com/aggbug/25.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Desirea Herrera</dc:creator>
            <guid>http://inphoteck.com/archive/2009/07/26/inversion-of-control.aspx</guid>
            <pubDate>Sun, 26 Jul 2009 17:04:32 GMT</pubDate>
            <wfw:comment>http://inphoteck.com/comments/25.aspx</wfw:comment>
            <comments>http://inphoteck.com/archive/2009/07/26/inversion-of-control.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://inphoteck.com/comments/commentRss/25.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Unit Testing Review List</title>
            <link>http://inphoteck.com/archive/2009/07/07/20.aspx</link>
            <description>&lt;img src="http://inphoteck.com/aggbug/20.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Desirea Herrera</dc:creator>
            <guid>http://inphoteck.com/archive/2009/07/07/20.aspx</guid>
            <pubDate>Tue, 07 Jul 2009 17:26:18 GMT</pubDate>
            <wfw:comment>http://inphoteck.com/comments/20.aspx</wfw:comment>
            <comments>http://inphoteck.com/archive/2009/07/07/20.aspx#feedback</comments>
            <wfw:commentRss>http://inphoteck.com/comments/commentRss/20.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Unit Testing in Visual Studio</title>
            <link>http://inphoteck.com/archive/2008/12/01/6.aspx</link>
            <description>&lt;p&gt;The more I learn, the more I know I don't know. As an MCT, it's my job to continually update my skills. To that end, I've been delving into things that aren't covered in the courses I teach.  Things like Unit Testing.&lt;/p&gt;
&lt;h3&gt;What's A Unit Test?&lt;/h3&gt;
&lt;p&gt;With Visual Studio 2005 and 2008, you get the ability in some versions like Team System to create a Test Project to do Unit Testing. Before I start talking about creating a unit test, let's review the basics. A unit test verifies that a function actually performs it's duties. Now, there are black box and white box types of tests. A black box test only tests that a function accepts only the datatypes it's designed to accept and returns the data or no data that it's expected to return.  In other words, you put in certain stuff and get certain stuff back. Now a white box test actually allows you to know what's going on between the input and output. White box testing ensures that you actually are testing all code pathways. It's called "Code Coverage".  For more information about Unit Testing you can check the following links:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://www.marcclifton.com/tabid/82/Default.aspx"&gt;Advanced Unit Testing Part 1&lt;/a&gt; &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://en.wikipedia.org/wiki/Unit_testing"&gt;Wikipedia on Unit Testing&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It's important to write your Unit Tests before you actually develop your application. After identifying the requirements of the application, a unit test can define the functionality of different pieces of the code before it's written. Unit testing helps to maintain the integrity of your code during refactoring. You'll always be able to test that the function still fulfills it's intended purpose.&lt;/p&gt;
&lt;h3&gt;Generating a Unit Test in Visual Studio&lt;/h3&gt;
&lt;p&gt;The simplest method of generating a unit test in Visual Studio is to right click the name of any method and select &lt;strong&gt;Create Unit Tests&lt;/strong&gt;. Be aware that not all versions of Visual Studio support Unit Testing. You can also create a new Test Project to add to the project and then, a test class can be added by either selecting from &lt;strong&gt;Add New Test&lt;/strong&gt; popup or by selecting &lt;strong&gt;Unit Test&lt;/strong&gt; from &lt;strong&gt;Add&lt;/strong&gt; menu. This brings up the &lt;strong&gt;Create Unit Tests&lt;/strong&gt; screen where multiple methods to be tested can be selected.&lt;/p&gt;
&lt;p&gt;Visual Studio only actually writes a basic stub for the Unit Test. It's up to you to fill in the blanks for the application. You'll do things like test that the return values are the correct datatype and within the expected value range. You'll also check to make sure the funciton only accepts the data it's suppose to accept. &lt;/p&gt;
&lt;p&gt;You'll normally see the following assert statement:&lt;br /&gt;
Assert.Inconclusive("A method that does not return a value cannot be verified.");&lt;/p&gt;
&lt;p&gt;If you ran the Unit Test for the method you're testing right now, You'd see the error message  "Assert.Inconclusive failed. A method that does not return a value cannot be verified." Now, if you comment out the Assert.Inconclusive statement, you'll have a test that passes because the unit test method isn't testing for anything. That's not going to help. &lt;/p&gt;
&lt;p&gt;You'll have to write some test code with the Assert statement. You'll be supplying the method with specific values and comparing the results with the expected result in an Assert statement. &lt;/p&gt;
&lt;h3&gt;Unit Test Design is Obviously Important&lt;/h3&gt;
&lt;p&gt;Obviously, did I say that again? Yup, I did. You've got to think of all possibilities going into the method and all coming out of the method. This takes some prior planning.  Now it might seem backwards based on what I've just said about right clicking a method and/or creating a Test Project to add to your application. The key is to think out your Unit Tests ahead of time so that you can implement them easily using Visual Studio. &lt;/p&gt;
&lt;p&gt;Additional Resources&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms182532.aspx"&gt;msdn.microsoft.com/en-us/library/ms182532.aspx&lt;/a&gt; &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.geekzone.co.nz/vs2008/4819"&gt;www.geekzone.co.nz/vs2008/4819&lt;/a&gt; &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.developingfor.net/visual-studio/first-foray-into-unit-testing-with-visual-studio-2008.html"&gt;www.developingfor.net/visual-studio/first-foray-into-unit-testing-with-visual-studio-2008.html&lt;/a&gt; &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.geekzone.co.nz/vs2008/4819"&gt;www.geekzone.co.nz/vs2008/4819&lt;/a&gt; &lt;/li&gt;
    &lt;li&gt;&lt;a href="http://haacked.com/archive/2008/07/22/unit-test-boundaries.aspx"&gt;haacked.com/archive/2008/07/22/unit-test-boundaries.aspx&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Good Luck Unit Testing&lt;/p&gt;
&lt;p&gt;I've written an additional Unit Testing Review with more links @ &lt;a id="viewpost_ascx_TitleUrl" title="Title of this entry." href="http://inphoteck.com/archive/2009/07/07/20.aspx"&gt;Unit Testing Review List&lt;/a&gt; &lt;font face="Arial"&gt; &lt;/font&gt;&lt;br /&gt;
&lt;/p&gt;&lt;img src="http://inphoteck.com/aggbug/6.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Desirea Herrera</dc:creator>
            <guid>http://inphoteck.com/archive/2008/12/01/6.aspx</guid>
            <pubDate>Mon, 01 Dec 2008 08:50:39 GMT</pubDate>
            <wfw:comment>http://inphoteck.com/comments/6.aspx</wfw:comment>
            <comments>http://inphoteck.com/archive/2008/12/01/6.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://inphoteck.com/comments/commentRss/6.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>