<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.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>Deborah's Developer MindScape : VB, Testing</title><link>http://msmvps.com/blogs/deborahk/archive/tags/VB/Testing/default.aspx</link><description>Tags: VB, Testing</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Running Your Unit Tests Continuously</title><link>http://msmvps.com/blogs/deborahk/archive/2012/09/26/running-your-unit-tests-continuously.aspx</link><pubDate>Wed, 26 Sep 2012 23:56:45 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1817407</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1817407</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2012/09/26/running-your-unit-tests-continuously.aspx#comments</comments><description>&lt;p&gt;One of the new unit testing features in VS 2012 (Premium or Ultimate) is the continuous test runner. When turned on, it automatically executes your unit tests after every successful build.&lt;/p&gt;  &lt;p&gt;Digressing a moment … in the early 1990&amp;#39;s Shari Lewis and Lamb Chop would sing a version of &amp;quot;The Song that Never Ends&amp;quot; at the end of each episode of their show. In memory of Lamb Chop:&lt;/p&gt;  &lt;p align="center"&gt;&lt;font color="#f79646"&gt;It is the test that never ends.     &lt;br /&gt;It goes on and on my friends.      &lt;br /&gt;Someone starting running it not knowing what it was,      &lt;br /&gt;and they&amp;#39;ll continue running it forever just because… &amp;lt;repeat&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;To turn on the continuous test runner, select the icon in the upper left corner of the Test Explorer:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3252.image_5F00_46A7E3D6.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6013.image_5F00_thumb_5F00_37FD37F1.png" width="491" height="174" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The tests will automatically execute asynchronously after each build. They also automatically run when first opening a solution containing the tests.&lt;/p&gt;  &lt;p&gt;NOTE: The tests are not executed after a build that is part of a Start With Debugging (F5) or Start Without Debugging operation.&lt;/p&gt;  &lt;p&gt;Any failed tests from previous runs are executed first. If they pass, the other (previously passed) tests are executed. If they fail, the other (previously passed) tests are not executed.&lt;/p&gt;  &lt;p&gt;This last point has caused me problems. I made a change that would have caused a previously passed tests to fail but I was not notified because I have some other failing tests. I had to manually run the tests in order for the previously passed tests to fail appropriately.&lt;/p&gt;  &lt;p&gt;Use the search feature of Test Explorer (&lt;a href="http://msmvps.com/blogs/deborahk/archive/2012/09/16/searching-and-grouping-in-vs-2012-test-explorer.aspx"&gt;detailed in this prior post&lt;/a&gt;) to filter the list of tests to execute.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1817407" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Test Explorer in Visual Studio 2012</title><link>http://msmvps.com/blogs/deborahk/archive/2012/09/16/test-explorer-in-visual-studio-2012.aspx</link><pubDate>Mon, 17 Sep 2012 00:30:02 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1816381</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1816381</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2012/09/16/test-explorer-in-visual-studio-2012.aspx#comments</comments><description>&lt;p&gt;One of the new things about testing in Visual Studio 2012 is that it is now available in *all* editions of Visual Studio all the way to Visual Studio Express!&lt;/p&gt;  &lt;p&gt;The Test Explorer in Visual&amp;#160; Studio 2012 replaces the Test View window in Visual Studio 2010. The following posts outline the Test Explorer features:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2012/09/15/layout-of-test-explorer-in-visual-studio-2012.aspx"&gt;Layout of Test Explorer in Visual Studio 2012&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2012/09/16/searching-and-grouping-in-vs-2012-test-explorer.aspx"&gt;Searching and Grouping in VS 2012 Test Explorer&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2012/09/16/101-ways-to-run-tests-with-visual-studio-2012.aspx"&gt;101 Ways to Run Tests with Visual Studio 2012&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2012/09/26/running-your-unit-tests-continuously.aspx"&gt;Running your Unit Tests Continuously&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1816381" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>101 Ways to Run Tests with Visual Studio 2012</title><link>http://msmvps.com/blogs/deborahk/archive/2012/09/16/101-ways-to-run-tests-with-visual-studio-2012.aspx</link><pubDate>Sun, 16 Sep 2012 20:59:09 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1816376</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1816376</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2012/09/16/101-ways-to-run-tests-with-visual-studio-2012.aspx#comments</comments><description>&lt;p&gt;OK 101 is an exaggeration, but there are many ways to run your tests in Visual Studio 2012.&lt;/p&gt;  &lt;h2&gt;From the test code file&lt;/h2&gt;  &lt;p&gt;While you are writing or editing a test method, you can right click anywhere within the method and run or debug the test.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6518.image_5F00_5C642DDC.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0753.image_5F00_thumb_5F00_261305CD.png" width="477" height="495" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;[Red rectangle added for illustration.]&lt;/p&gt;  &lt;p&gt;All of the tests in Test Explorer are displayed &amp;quot;grayed out&amp;quot; except for the executed test as shown below. Click on the test to view the result details in the right pane (or bottom pane if your Test Explorer is sized to display vertically).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/5700.image_5F00_79F608DB.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0131.image_5F00_thumb_5F00_6B4B5CF6.png" width="480" height="204" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;From the code editor, you can also run all of the tests within a code file by right-clicking anywhere within the code file, but outside of a specific method. Clicking in an empty space between two methods, for example, will execute all of the tests in the code file.&lt;/p&gt;  &lt;h2&gt;From Test Explorer Toolbar&lt;/h2&gt;  &lt;p&gt;View the Test Explorer window using Test | Windows | Test Explorer. The Test Explorer window toolbar provides many ways to run your tests.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/8156.image_5F00_0A8E03CA.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3113.image_5F00_thumb_5F00_296477A8.png" width="493" height="193" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Run All&lt;/strong&gt;       &lt;br /&gt;Runs all of the tests displayed in Test Explorer. If the list of tests are filtered by search criteria, only the filtered tests are executed. (See &lt;a href="http://msmvps.com/blogs/deborahk/archive/2012/09/16/searching-and-grouping-in-vs-2012-test-explorer.aspx"&gt;this prior blog post&lt;/a&gt; for information on searching within Test Explorer.) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Run Failed Tests&lt;/strong&gt;       &lt;br /&gt;Runs only the failed tests displayed in Test Explorer. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Run Not Run Tests&lt;/strong&gt;       &lt;br /&gt;Only runs the tests displayed in Test Explorer which were not previously run since opening Visual Studio. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Run Passed Tests&lt;/strong&gt;       &lt;br /&gt;Runs only the passed tests displayed in Test Explorer. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Repeat Last Run&lt;/strong&gt;       &lt;br /&gt;Runs the prior test run again, but only on the files displayed in Test Explorer. If you Run All then filter the tests in Test Explorer then Repeat Last Run, only the filtered tests will be executed again. &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;From Test Explorer Context Menu&lt;/h2&gt;  &lt;p&gt;Right-clicking on a test in Test Explorer provides run options.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/7026.image_5F00_5D98A0EE.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/4152.image_5F00_thumb_5F00_7CDB47C1.png" width="466" height="285" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can select a single test, multiple tests using the Ctrl and Shift keys, or all tests using the Select All option from the context menu. Then you can Run or Debug the selected tests.&lt;/p&gt;  &lt;p&gt;Use these techniques to run only the tests you are interested in.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1816376" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Searching and Grouping in VS 2012 Test Explorer</title><link>http://msmvps.com/blogs/deborahk/archive/2012/09/16/searching-and-grouping-in-vs-2012-test-explorer.aspx</link><pubDate>Sun, 16 Sep 2012 19:59:50 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1816374</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1816374</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2012/09/16/searching-and-grouping-in-vs-2012-test-explorer.aspx#comments</comments><description>&lt;p&gt;Visual Studio 2012 Test Explorer has extensive searching and limited grouping capabilities. (Visual Studio 2010&amp;#39;s Test View window had more grouping options by way of its many sorting parameters.)&lt;/p&gt;  &lt;h2&gt;Searching&lt;/h2&gt;  &lt;p&gt;Entering text into the Test Explorer Search box filters the list of tests to those containing the entered text. In the example below, entering &amp;quot;customer&amp;quot; in the search box filters the list to all test names containing &amp;quot;customer&amp;quot;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/1184.image_5F00_0DC5C163.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/7701.image_5F00_thumb_5F00_7F1B157D.png" width="484" height="190" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;By default, the search matches within the test name, but there are other choices. To view the other options, click the down arrow to the right of the Search box in the toolbar as shown below. Even though it looks a little like one large option name, these are actually three options:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Test File Path &lt;/li&gt;    &lt;li&gt;Fully Qualified Name &lt;/li&gt;    &lt;li&gt;Test Result &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/4276.image_5F00_452BD291.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0410.image_5F00_thumb_5F00_6B8DB5DC.png" width="487" height="191" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Select one of these options, then type the search parameter within the provided quotation marks. Press the Enter key to execute the search.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/2480.image_5F00_6A491CFD.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3580.image_5F00_thumb_5F00_42A2A0D3.png" width="492" height="209" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Test File Path&lt;/strong&gt; searches the paths to the test code files. In this example, the tests are in two components in two different directories:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;C:\Users\Deborah\Speaking\Other\AcmeCustomerManagement_BestKeptSecrets_2012\ACM.LibraryCSharpTest &lt;/li&gt;    &lt;li&gt;C:\Users\Deborah\Speaking\Other\AcmeCustomerManagement_BestKeptSecrets_2012\ACM.BLCSharpTest &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The above example finds all of the tests in the LibraryCSharpTest component.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Fully Qualified Name&lt;/strong&gt; searches the path and file name.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Test Result&lt;/strong&gt; has several valid search parameters: &amp;quot;Not Run&amp;quot;, &amp;quot;Skipped&amp;quot;, &amp;quot;Passed&amp;quot; or &amp;quot;Failed&amp;quot;. These options filter the list to defined&amp;#160; test outcome.&lt;/p&gt;  &lt;h2&gt;Grouping&lt;/h2&gt;  &lt;p&gt;By default, the Test Explorer groups the tests by test outcome as shown in the prior screen shots. The only other group-by option is by duration. This groups by the time it took to execute the test.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3808.image_5F00_76D6CA19.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3426.image_5F00_thumb_5F00_161970ED.png" width="500" height="213" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Use these techniques to filter and group the tests in the Test Explorer window.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;p&gt;EDITED 9/28/12 to correct typographical errors.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1816374" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Layout of Test Explorer in Visual Studio 2012</title><link>http://msmvps.com/blogs/deborahk/archive/2012/09/15/layout-of-test-explorer-in-visual-studio-2012.aspx</link><pubDate>Sun, 16 Sep 2012 01:18:47 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1816355</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1816355</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2012/09/15/layout-of-test-explorer-in-visual-studio-2012.aspx#comments</comments><description>&lt;p&gt;In Visual Studio 2012, the Visual Studio 2010 Test View window has been replaced by a new Test Explorer window.&lt;/p&gt;  &lt;p&gt;By default, it appears on the left side of the Visual Studio Interactive Development Environment (IDE) as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6232.image_5F00_34357AEE.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/4520.image_5F00_thumb_5F00_16E02324.png" width="490" height="350" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;(Red box added for illustration)&lt;/p&gt;  &lt;p&gt;When you run the unit tests, the result appears in the bottom panel of the Test Explorer window:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/2818.image_5F00_6337B6C5.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/1307.image_5F00_thumb_5F00_7AEEEE2B.png" width="475" height="340" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Since many unit tests may have the same prefix and a long and descriptive name, docking the Test Explorer on the left often cuts off the unique portions of the names. Instead of making the window wider, consider moving it to the bottom:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3343.image_5F00_52700C17.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3487.image_5F00_thumb_5F00_2D724B9E.png" width="489" height="327" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;(Red box added for illustration)&lt;/p&gt;  &lt;p&gt;The test results now appear in the right panel of the Test Explorer window:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3302.image_5F00_257AA93C.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6567.image_5F00_thumb_5F00_64D85CCC.png" width="493" height="198" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Moving the Test Explorer window from the left side to the bottom gives you more horizontal space to view the tests and their execution times. It also gives you more space to view the test results.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1816355" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Visual+Studio/default.aspx">Visual Studio</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>VS 2010: Test View Error</title><link>http://msmvps.com/blogs/deborahk/archive/2010/04/21/vs-2010-test-view-error.aspx</link><pubDate>Thu, 22 Apr 2010 04:01:49 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1764003</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1764003</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2010/04/21/vs-2010-test-view-error.aspx#comments</comments><description>&lt;p&gt;I was working on an application in Visual Studio 2010 today, opened the Test View window and got an exception as shown below.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://blogs.msdn.com/blogfiles/charles_sterling/WindowsLiveWriter/TestViewIssueAnexceptionwasencounteredwh_BBE6/image_8.png" width="506" height="404" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;Here is the first part of the error in text: &amp;quot;An exception was encountered while constructing the content of this frame...&amp;quot;&lt;/p&gt;  &lt;p&gt;With the help of Chuck Sterling, I got an answer on how to fix the problem. It is detailed here:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://blogs.msdn.com/charles_sterling/archive/2010/04/21/test-view-issue-an-exception-was-encountered-while-constructing-the-content-of-this-frame.aspx" href="http://blogs.msdn.com/charles_sterling/archive/2010/04/21/test-view-issue-an-exception-was-encountered-while-constructing-the-content-of-this-frame.aspx"&gt;http://blogs.msdn.com/charles_sterling/archive/2010/04/21/test-view-issue-an-exception-was-encountered-while-constructing-the-content-of-this-frame.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Thanks Chuck!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1764003" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Unit Testing: Exposing Private Members</title><link>http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-exposing-private-members.aspx</link><pubDate>Thu, 29 Oct 2009 23:19:53 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1736232</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1736232</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-exposing-private-members.aspx#comments</comments><description>&lt;p&gt;Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development and execution of unit tests. It is, of&amp;#160; course, easy for your tests to access the public properties and methods of your classes. But what about those private members?&lt;/p&gt;  &lt;p&gt;[To begin with an overview of unit testing, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-an-introduction.aspx"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;[To expose internal (C#) or friend (VB) members, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-exposing-internal-friend-members.aspx"&gt;see this post&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;You may have properties or methods in your class defined&amp;#160; to be private. This post details how to test those methods using the unit testing features in Visual Studio.&lt;/p&gt;  &lt;p&gt;NOTE: There are some testing philosophies that recommend you never test your private members; rather you test the public/internal/friend members and assume that those will provide coverage for all of your private members as well. Regardless of your point of view on this topic, this post provides the how-to so you can decide for yourself whether you want to or not. &lt;/p&gt;  &lt;p&gt;Let&amp;#39;s say your Customer class has a CustomerId property that looks like this:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;private int? _CustomerId;     &lt;br /&gt;public int? CustomerId      &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; get { return _CustomerId; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;strong&gt;private&lt;/strong&gt; set      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_CustomerId == null || !_CustomerId.Equals(value))      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string propertyName = &amp;quot;CustomerId&amp;quot;;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (!_CustomerId.Equals(value))      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _CustomerId = value;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Private _CustomerId As Integer?     &lt;br /&gt;Public Property CustomerId() As Integer?      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _CustomerId      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Get      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;strong&gt;Private&lt;/strong&gt; Set(ByVal value As Integer?)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _CustomerId Is Nothing OrElse _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Not _CustomerId.Equals(value) Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim propertyName As String = &amp;quot;CustomerId&amp;quot;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If Not _CustomerId.Equals(value) Then      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _CustomerId = value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Set      &lt;br /&gt;End Property&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Notice in both cases, the setter is private. The expectation is that the business object will set this value. However, you can you unit test it if you cannot set it?&lt;/p&gt;  &lt;p&gt;The answer is &lt;strong&gt;PrivateObject&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;PrivateObject is a class that allows test code to call class members that are not public. You PrivateObject to access private members of your class in your unit tests.&lt;/p&gt;  &lt;p&gt;NOTE: You can also use PrivateObject for other non-public class members.&lt;/p&gt;  &lt;p&gt;The following demonstrates how to use PrivateObject.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;/// &amp;lt;summary&amp;gt;     &lt;br /&gt;///A test for CustomerId      &lt;br /&gt;///&amp;lt;/summary&amp;gt;      &lt;br /&gt;[TestMethod()]      &lt;br /&gt;public void CustomerIdTest()      &lt;br /&gt;{      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Customer target;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int? expected;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int? actual; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; // Null to Value     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = new Customer();      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = 42; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; PrivateObject po = new PrivateObject(target);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; po.SetProperty(&amp;quot;CustomerId&amp;quot;, expected);      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.CustomerId;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;);      &lt;br /&gt;}&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#39;&amp;#39;&amp;#39;&amp;lt;summary&amp;gt;     &lt;br /&gt;&amp;#39;&amp;#39;&amp;#39;A test for CustomerId      &lt;br /&gt;&amp;#39;&amp;#39;&amp;#39;&amp;lt;/summary&amp;gt;      &lt;br /&gt;&amp;lt;TestMethod()&amp;gt; _      &lt;br /&gt;Public Sub CustomerIdTest()      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim target As Customer      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim expected As Integer?      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim actual As Integer? &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Null to value     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = New Customer      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = 42 &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Dim po As PrivateObject = New PrivateObject(target)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; po.SetProperty(&amp;quot;CustomerId&amp;quot;, expected)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.CustomerId      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;)      &lt;br /&gt;End Sub&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;NOTE: This is only part of the code you would need to fully test the CustomerId property.&amp;#160; Only one testing scenario was covered to instead focus on the PrivateObject syntax.&lt;/p&gt;  &lt;p&gt;The code creates a new instance of PrivateObject, passing the instance of the class that has the private member you wish to access.&lt;/p&gt;  &lt;p&gt;PrivateObject has methods such as GetProperty, SetProperty, GetField, SetField, and Invoke. These methods provide access to the private or other&amp;#160; non-public members of your class.&lt;/p&gt;  &lt;p&gt;Use PrivateObject whenever you need to access a private member in your class from your unit testing code.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1736232" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Unit Testing: Exposing Internal/Friend Members</title><link>http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-exposing-internal-friend-members.aspx</link><pubDate>Thu, 29 Oct 2009 22:23:55 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1736218</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1736218</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-exposing-internal-friend-members.aspx#comments</comments><description>&lt;p&gt;Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development and execution of unit tests. It is, of&amp;#160; course, easy for your tests to access the public properties and methods of your classes. But what about those internal/friend members?&lt;/p&gt;  &lt;p&gt;[To begin with an overview of unit testing, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-an-introduction.aspx"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;[To expose private members, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-exposing-private-members.aspx"&gt;see this post&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;You may have properties or methods in your class defined&amp;#160; to be internal (C#) or friend (VB). This post details how to test those methods using the unit testing features in Visual Studio.&lt;/p&gt;  &lt;p&gt;Well, it is easy. You just need to use this line of code:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;[assembly: InternalsVisibleTo(&amp;quot;BoTest&amp;quot;)]&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;lt;Assembly: InternalsVisibleTo(&amp;quot;BoTest&amp;quot;)&amp;gt;&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;Where &lt;strong&gt;BoTest&lt;/strong&gt; is the name of your unit testing project.&lt;/p&gt;  &lt;p&gt;The hard part is finding where you put this line of code. It should reside in your AssemblyInfo file.&lt;/p&gt;  &lt;p&gt;This file is relatively easy to find in your C# project; not so easy to find in your VB project. Here are the steps for both.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Find the project you want to test in Solution Explorer. &lt;/li&gt;    &lt;li&gt;Open the Properties node. &lt;/li&gt;    &lt;li&gt;Double-click on the AssemblyInfo.cs file. &lt;/li&gt;    &lt;li&gt;Set the InternalsVisibleTo attribute into the AssemblyInfo.cs file. &lt;/li&gt;    &lt;li&gt;Rebuild the project. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Find the project you want to test in Solution Explorer. &lt;/li&gt;    &lt;li&gt;Click on the Show All Files button in the Solution Explorer toolbar. &lt;/li&gt;    &lt;li&gt;Open the My Project node &lt;/li&gt;    &lt;li&gt;Double-click on the AssemblyInfo.vb file. &lt;/li&gt;    &lt;li&gt;Set the InternalsVisibleTo attribute into the AssemblyInfo.vb file. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Use this technique whenever you have internal/friend members in a class that you wish to access with your unit testing code.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1736218" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Unit Testing: Testing Properties</title><link>http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-testing-properties.aspx</link><pubDate>Thu, 29 Oct 2009 22:01:14 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1736213</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1736213</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-testing-properties.aspx#comments</comments><description>&lt;p&gt;Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development and execution of unit tests. This post provides suggestions for testing your property getters and setters.&lt;/p&gt;  &lt;p&gt;[To begin with an overview of unit testing, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-an-introduction.aspx"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;Let&amp;#39;s say your Customer class has a LastName property that looks like this:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; private string _LastName;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public string LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return _LastName; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_LastName == null || _LastName != value)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string propertyName = &amp;quot;LastName&amp;quot;;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Perform any validation here&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_LastName != value)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName = value;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; propertyName);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;(Someone just mentioned how all of those ending braces look like a flock of sea gulls! LOL!)&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _LastName As String      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property LastName() As String       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As String)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _LastName Is Nothing OrElse _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName IsNot value Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim propertyName As String = &amp;quot;LastName&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Perform any validation       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _LastName IsNot value Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; propertyName)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;NOTE: The &lt;strong&gt;SetEntityState&lt;/strong&gt; method used in this code is coming from the business object base class provided in &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx"&gt;this prior post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The key step for developing a good unit test is to define the test scenarios. &lt;/p&gt;  &lt;p&gt;Looking at the requirements, the following testing scenarios are required for the LastName property:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Initial null value; set to null value (should perform validation but not set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial null value; set to valid&amp;#160; string (should perform validation and set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial null value; set to empty string (should perform validation and set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial string value; set to null value (should perform validation and set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial string value, set to different string value (should perform validation and set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial string value, set&amp;#160; to same string value (should not&amp;#160; perform validation and not set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial string value, set&amp;#160; to empty value (should perform validation and set the dirty flag) &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;And if you have validation code, you will have more scenarios to test valid and invalid values. But this is enough to give you the general idea.&lt;/p&gt;  &lt;p&gt;If you are building the unit test from existing code, you can generate the basic structure of the unit test for the property following the techniques detailed in &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-an-introduction.aspx"&gt;this prior post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;But the test generation only gives you the basic template for testing your properties. This post focuses on how to update that template to perform the required unit testing.&lt;/p&gt;  &lt;p&gt;Visual Studio will generate the following unit test template for the LastName property that was shown at the beginning of this post:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;/// &amp;lt;summary&amp;gt;      &lt;br /&gt;///A test for LastName       &lt;br /&gt;///&amp;lt;/summary&amp;gt;       &lt;br /&gt;[TestMethod()]       &lt;br /&gt;public void LastNameTest()       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Customer target = new Customer(); // TODO: Initialize to an appropriate value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string expected = string.Empty; // TODO: Initialize to an appropriate value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string actual;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.Inconclusive(&amp;quot;Verify the correctness of this test method.&amp;quot;);       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#39;&amp;#39;&amp;#39;&amp;lt;summary&amp;gt;      &lt;br /&gt;&amp;#39;&amp;#39;&amp;#39;A test for LastName       &lt;br /&gt;&amp;#39;&amp;#39;&amp;#39;&amp;lt;/summary&amp;gt;       &lt;br /&gt;&amp;lt;TestMethod()&amp;gt; _       &lt;br /&gt;Public Sub LastNameTest()       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim target As Customer = New Customer &amp;#39; TODO: Initialize to an appropriate value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim expected As String = String.Empty &amp;#39; TODO: Initialize to an appropriate value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim actual As String       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.Inconclusive(&amp;quot;Verify the correctness of this test method.&amp;quot;)       &lt;br /&gt;End Sub&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;To cover the defined testing scenarios, this code needs to be enhanced as follows:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;/// &amp;lt;summary&amp;gt;      &lt;br /&gt;///A test for LastName       &lt;br /&gt;///&amp;lt;/summary&amp;gt;       &lt;br /&gt;[TestMethod()]       &lt;br /&gt;public void LastNameTest()       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Customer target;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string expected;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string actual; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Null to Null      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = new Customer();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = null;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(false, target.IsDirty,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;quot;Object not marked as dirty&amp;quot;); &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; // Null to value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = new Customer();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = &amp;quot;Johnson&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(true, target.IsDirty, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;); &lt;/font&gt;&lt;/p&gt; &lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; // Null to Empty    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = new Customer();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = string.Empty;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(true, target.IsDirty,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;); &lt;/font&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; // Value to Null      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = new Customer() {LastName = &amp;quot;Johnson&amp;quot;};       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.SetEntityState(BoBase.EntityStateType.Unchanged);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = null;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(true, target.IsDirty,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;); &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; // Value to new Value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = new Customer() {LastName = &amp;quot;Johnson&amp;quot;};       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.SetEntityState(BoBase.EntityStateType.Unchanged);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = &amp;quot;Jones&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(true, target.IsDirty,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;); &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; // Value to same Value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = new Customer() {LastName = &amp;quot;Johnson&amp;quot;};       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.SetEntityState(BoBase.EntityStateType.Unchanged);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = &amp;quot;Johnson&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(false, target.IsDirty,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;);&lt;/font&gt;&lt;/p&gt; &lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; // Value to Empty    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = new Customer() {LastName = &amp;quot;Johnson&amp;quot;};     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.SetEntityState(BoBase.EntityStateType.Unchanged);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = string.Empty;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(true, target.IsDirty,&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;);&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;   &lt;br /&gt;}&lt;/font&gt;   &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#39;&amp;#39;&amp;#39;&amp;lt;summary&amp;gt;      &lt;br /&gt;&amp;#39;&amp;#39;&amp;#39;A test for LastName       &lt;br /&gt;&amp;#39;&amp;#39;&amp;#39;&amp;lt;/summary&amp;gt;       &lt;br /&gt;&amp;lt;TestMethod()&amp;gt; _       &lt;br /&gt;Public Sub LastNameTest()       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim target As Customer       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim expected As String       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim actual As String &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Null to Null      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = New Customer       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = Nothing       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(False, target.IsDirty, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Null to value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = New Customer       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = &amp;quot;Johnson&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(True, target.IsDirty, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;) &lt;/font&gt;&lt;/p&gt; &lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Null to Empty    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = New Customer     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = String.Empty     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(True, target.IsDirty, _     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;) &lt;/font&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Value to Null      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = New Customer With {.LastName = &amp;quot;Johnson&amp;quot;}       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.SetEntityState(BOBase.EntityStateType.Unchanged)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = Nothing       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(True, target.IsDirty, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Value to new Value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = New Customer With {.LastName = &amp;quot;Johnson&amp;quot;}       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.SetEntityState(BOBase.EntityStateType.Unchanged)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = &amp;quot;Jones&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(True, target.IsDirty, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Value to same Value      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = New Customer With {.LastName = &amp;quot;Johnson&amp;quot;}       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.SetEntityState(BOBase.EntityStateType.Unchanged)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = &amp;quot;Johnson&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(False, target.IsDirty, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;)&lt;/font&gt;&lt;/p&gt; &lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Value to Empty    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target = New Customer With {.LastName = &amp;quot;Johnson&amp;quot;}     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; expected = String.Empty     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual, &amp;quot;Values are not equal&amp;quot;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(True, target.IsDirty, _     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;Object not marked as dirty&amp;quot;) &lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;   &lt;br /&gt;End Sub&lt;/font&gt;   &lt;p&gt;NOTE: The &lt;strong&gt;SetEntityState&lt;/strong&gt; method and &lt;strong&gt;IsDirty&lt;/strong&gt; property used in this code are coming from the business object base class provided in &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx"&gt;this prior post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;NOTE: You may get an error when calling &lt;strong&gt;SetEntityState&lt;/strong&gt; because in the business object base class is defined to be protected internal (protected friend in VB), not public. If so, you need to use the technique presented here to allow your tests to access internal/friend properties and methods.&lt;/p&gt;  &lt;p&gt;WOW! That is a LOT of test code! Some experts have said that every line of code needs at least 3 - 5 lines of test code.&lt;/p&gt;  &lt;p&gt;We have 17 lines of C# code and 15 lines of VB code in our property procedure. If I counted correctly, there are 51 lines of C# test code and 50 lines&amp;#160; of VB test code. So that is about 3x the number of code lines.&lt;/p&gt;  &lt;p&gt;Let&amp;#39;s walk through what this test code is doing, following through with the testing scenarios provided earlier in this post.&lt;/p&gt;  &lt;p&gt;Scenario 1: The code creates a new instance of the Customer class. By default, a new instance sets any string values to null/nothing. So the test code simply sets the property to null/nothing, gets the value, confirms that the value is as expected, and ensures that it did not get marked as dirty.&lt;/p&gt;  &lt;p&gt;Scenario 2: The code again creates a new instance of the Customer class. By default a new instance sets any string values to null/nothing. So the test code sets the property to a value, gets the value, confirms that the value is as expected, and ensures that the object was marked as dirty.&lt;/p&gt;  &lt;p&gt;Scenario 3: The code again creates a new instance of the Customer class. By default a new instance sets any string values to null/nothing. So the test code sets the property to an empty string, gets the value, confirms that the value is as expected, and ensures that the object was marked as dirty.&lt;/p&gt;  &lt;p&gt;Now for the harder scenarios. There is no easy way to set a non-null initial value for a property. One option is to set the private backing variable to the desired initial value. But with the backing variable being private, there is extra code to write to make it work. &lt;/p&gt;  &lt;p&gt;Another option is to set the property using the setter. But this marks&amp;#160; the object as dirty, adversely interfering with the test. So if you use this technique, you then need to call SetEntityState to clear the entity state and ensure it is not marked as dirty. The sample code used this technique.&lt;/p&gt;  &lt;p&gt;Scenario 4: The code creates a new instance of the customer class, setting the initial value of the property to a valid value. It then calls SetEntityState to clear the dirty flag. Then the test code sets the property to a null, gets the value, confirms that the value is as expected, and ensures that the object was marked as dirty.&lt;/p&gt;  &lt;p&gt;Scenario 5: The code creates a new instance of the customer class, setting the initial value of the property to a valid value. It then calls SetEntityState to clear the dirty flag. Then the test code sets the property to another valid value, gets the value, confirms that the value is as expected, and ensures that the object was marked as dirty.&lt;/p&gt;  &lt;p&gt;Scenario 6: The code creates a new instance of the customer class, setting the initial value of the property to a valid value. It then calls SetEntityState to clear the dirty flag. Then the test code sets the property to the same value, gets the value, confirms that the value is as expected, and ensures that the object was &lt;em&gt;not&lt;/em&gt; marked as dirty.&lt;/p&gt;  &lt;p&gt;Scenario 7: The code creates a new instance of the customer class, setting the initial value of the property to a valid value. It then calls SetEntityState to clear the dirty flag. Then the test code sets the property to an empty string, gets the value, confirms that the value is as expected, and ensures that the object was marked as dirty.&lt;/p&gt;  &lt;p&gt;If the field was validated, such as required field validation or a maximum length check, additional scenarios and associated test code would be required.&lt;/p&gt;  &lt;p&gt;So for every business object property in your application, define the appropriate set of test scenarios and build the test code to support each scenario.&lt;/p&gt;  &lt;p&gt;Or build a test base class that performs the basic set of tests for each of your properties. But that is left for a future post.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1736213" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Unit Testing: Code Coverage</title><link>http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-code-coverage.aspx</link><pubDate>Sun, 25 Oct 2009 23:27:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1735168</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1735168</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-code-coverage.aspx#comments</comments><description>&lt;p&gt;Visual Studio 2008 (Team System ONLY) provides a really nice set of tools for viewing the code coverage of your unit tests. &lt;/p&gt;  &lt;p&gt;NOTE: While Visual Studio 2008 Professional Edition has tools for building, executing, and debugging unit tests, it does NOT include the code coverage tools.&lt;/p&gt;  &lt;p&gt;[To begin with an overview of unit testing, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-an-introduction.aspx"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;Code coverage illustrates how much of the code was executed (or covered) by the unit tests.&lt;/p&gt;  &lt;p&gt;NOTE: This post assumes you have already generated or created at least one unit test.&lt;/p&gt;  &lt;p&gt;To view the code coverage for your unit tests:&lt;/p&gt;  &lt;p&gt;1) Enable code coverage in the test run configuration file.&lt;/p&gt;  &lt;p&gt;When you create your first unit test, Visual Studio adds a LocalTestRun.testrunconfig file to your solution under the Solution Items folder. Double-click on this file to open it:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6661.image_5F00_3A9D88EC.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/7635.image_5F00_thumb_5F00_193DE350.png" width="462" height="353" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Select Code Coverage from the left list:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/1362.image_5F00_16B4B192.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6253.image_5F00_thumb_5F00_0A468E69.png" width="466" height="356" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Select the files on the right that you wish to view code coverage. Don&amp;#39;t pick your test projects; rather pick the projects containing the code that is being tested. Then click Apply and Close.&lt;/p&gt;  &lt;p&gt;2) Run your unit tests. The Test Results dialog appears.&lt;/p&gt;  &lt;p&gt;See &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-execution.aspx"&gt;this prior post&lt;/a&gt; for more information on executing unit tests.&lt;/p&gt;  &lt;p&gt;Your results should appear similar to the following:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/4503.image_5F00_01E2B912.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/8625.image_5F00_thumb_5F00_12E6E6F5.png" width="483" height="82" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3) If the tests pass, click the Show Code Coverage Results button in the far upper right corner of the Test Results dialog. The Code Coverage Results dialog appears.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0777.image_5F00_38DC974B.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/5483.image_5F00_thumb_5F00_698F9EF6.png" width="477" height="264" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This dialog displays all of the code in all of the files you selected for code coverage instrumentation. Drill down as needed to find the desired code.&lt;/p&gt;  &lt;p&gt;In this case, the unit test is testing the getter and setter for the LastName. Notice&amp;#160; that the covered percentage for both the getter and setter is 100%. That means that the unit test is executing every line of code in the getter and setter.&lt;/p&gt;  &lt;p&gt;4) Double click on any item in the Code Coverage dialog to open the associated code window.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6153.image_5F00_6440B845.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0777.image_5F00_thumb_5F00_22C605EC.png" width="479" height="404" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Notice how the code is color-coded. Blue shows code that was executed by the unit test. Red shows code that was not executed.&lt;/p&gt;  &lt;p&gt;Use this feature to ensure you have unit tests for each unit of your code.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;p&gt;EDITED 10/27/09: While Visual Studio 2008 Professional Edition has tools for building, executing, and debugging unit tests, it does NOT include the code coverage tools. In the original version of this post, I incorrectly stated that code coverage tools were available in the Professional Edition. This post has been corrected.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1735168" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Unit Testing: Execution</title><link>http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-execution.aspx</link><pubDate>Sun, 25 Oct 2009 22:50:44 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1735158</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1735158</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-execution.aspx#comments</comments><description>&lt;p&gt;Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development and execution of unit tests.&lt;/p&gt;  &lt;p&gt;[To begin with an overview of unit testing, &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-an-introduction.aspx"&gt;start here&lt;/a&gt;.]&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-an-introduction.aspx"&gt;This prior post&lt;/a&gt; demonstrates how to build a unit test using the &amp;quot;Create Unit Tests...&amp;quot; feature of the Code Editor. This post demonstrates how to execute a unit test.&lt;/p&gt;  &lt;p&gt;NOTE: This post assumes you have already generated or created at least one unit test.&lt;/p&gt;  &lt;p&gt;To execute one or more unit tests:&lt;/p&gt;  &lt;p&gt;1) Open your solution in Visual Studio.&lt;/p&gt;  &lt;p&gt;The solution should include both the project(s) to test and the test project(s).&lt;/p&gt;  &lt;p&gt;2) Select Test | Windows | Test View from the menu to view the Test View window. This window contains every method marked with the TestMethod attribute.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/2620.image_5F00_27D6A4F6.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6518.image_5F00_thumb_5F00_40561C79.png" width="457" height="247" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The solution used for the screenshot above has two LastNameTest unit tests: One for the VB example and one for the C# example. If you coded along&amp;#160; from the prior unit testing post, you will only have one for whichever language you selected. If you have been creating unit tests for one of your projects, you may have hundreds of tests in this list.&lt;/p&gt;  &lt;p&gt;To execute unit tests:&lt;/p&gt;  &lt;p&gt;1) Select one or&amp;#160; more tests from the list of tests in the Test View window.&lt;/p&gt;  &lt;p&gt;You can add columns and sort the list or use the filter feature to make it easier to locate and select the desired tests to execute.&lt;/p&gt;  &lt;p&gt;2) Click the Run Selection button in the upper left&amp;#160; corner of the Test View window or right-click on any selected test and select &amp;quot;Run Selection&amp;quot; from the context menu.&lt;/p&gt;  &lt;p&gt;The selected test(s) will then execute, displaying their status in the Test Results window:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6180.image_5F00_543F8942.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/4428.image_5F00_thumb_5F00_0A145890.png" width="505" height="142" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;When the test is complete, the Test Results window will look something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/2055.image_5F00_1967BA9F.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0777.image_5F00_thumb_5F00_75EB1639.png" width="499" height="128" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Both of&amp;#160; the tests shown in the above screenshot are marked as Inconclusive because the generated unit testing code used the Assert class Inconclusive method. The generated unit testing template is designed to prevent a false positive. It generates an inconclusive result until you update the unit test with correct valid and invalid values and remove the Inconclusive method call.&lt;/p&gt;  &lt;p&gt;To see more information on the result of the test, double-click on a test result.&lt;/p&gt;  &lt;p&gt;To run the test again, use the Run or Debug buttons at the top of the Test Results window.&lt;/p&gt;  &lt;p&gt;If any of&amp;#160; the tests don&amp;#39;t pass, they are marked as Failed in the Test Results window as shown below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/2475.image_5F00_57047C8E.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/5684.image_5F00_thumb_5F00_6A719095.png" width="499" height="138" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Double click on any of&amp;#160; the failed tests to view the test results:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/1033.image_5F00_085F78BD.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/2502.image_5F00_thumb_5F00_1A9819B2.png" width="475" height="389" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The Error Stack Trace at the bottom of this window gives you further information on the source of the failure. Click on any link in the stack trace to jump to the associated location in the code.&lt;/p&gt;  &lt;p&gt;You can also debug the code as the test is executing if you &amp;quot;Debug Selection&amp;quot; option instead of the &amp;quot;Run Selection&amp;quot; option.&lt;/p&gt;  &lt;p&gt;After you update the unit tests with valid code and the tests pass, the Test Results will appear as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/3755.image_5F00_617116E2.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6215.image_5F00_thumb_5F00_11B7EB99.png" width="473" height="131" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Notice the color-coded green passing indicator.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1735158" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item><item><title>Unit Testing: An Introduction</title><link>http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-an-introduction.aspx</link><pubDate>Sun, 25 Oct 2009 21:04:20 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1735139</guid><dc:creator>Deborah Kurata</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/deborahk/rsscomments.aspx?PostID=1735139</wfw:commentRss><comments>http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-an-introduction.aspx#comments</comments><description>&lt;p&gt;If you have Visual Studio 2008 or later and have the Professional Edition or better (NOT the Express Editions), you have some very nice unit testing tools within your Visual Studio environment. These tools help you write, execute, and track your unit tests and code coverage. This post provides an introduction to using these tools.&lt;/p&gt;  &lt;p&gt;If you are new to unit testing, the idea is to test the smallest possible units of your code. In most cases, the smallest units of code are the property procedures and methods of your classes.&lt;/p&gt;  &lt;p&gt;For more general information about the purpose of unit testing, see &lt;a href="http://en.wikipedia.org/wiki/Unit_testing"&gt;this link&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;NOTE: Unit testing is not meant to replace integration testing, system testing, or user testing.&lt;/p&gt;  &lt;p&gt;In some development methodologies, such as Test Driven Development (TDD), unit tests are written &lt;em&gt;before&lt;/em&gt; the code is written. You capture the basic requirements in the unit test and then write the code. The code is complete when the unit tests&amp;#160; pass. Visual Studio 2010 has features to assist with this &amp;quot;unit test first&amp;quot; approach.&lt;/p&gt;  &lt;p&gt;But&amp;#160; this introduction demonstrates how to write unit tests for &lt;em&gt;existing&lt;/em&gt; code. This technique is helpful if you follow a code-first approach or if you received code from another source or have old code that did not originally have unit tests.&lt;/p&gt;  &lt;h2&gt;Build the Code&lt;/h2&gt;  &lt;p&gt;The business object tested in this post is a simplified Customer class that uses the business object base class defined in &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx"&gt;this post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The Customer class is shown below.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;public class Customer: BoBase      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; private int? _CustomerId;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public int? CustomerId       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return _CustomerId; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; internal set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_CustomerId == null || !_CustomerId.Equals(value))       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string propertyName = &amp;quot;CustomerId&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;// Perform any validation here      &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (!_CustomerId.Equals(value))      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _CustomerId = value;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; propertyName);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; private string _LastName;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public string LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return _LastName; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_LastName == null || _LastName != value)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string propertyName = &amp;quot;LastName&amp;quot;;&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Perform any validation here&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_LastName != value)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName = value;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; propertyName);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; private string _FirstName;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public string FirstName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return _FirstName; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_FirstName == null || _FirstName != value)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string propertyName = &amp;quot;FirstName&amp;quot;;&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Perform any validation here&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_FirstName != value)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _FirstName = value;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; propertyName);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; } &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; private string _EmailAddress;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; public string EmailAddress       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; get { return _EmailAddress; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_EmailAddress == null || _EmailAddress != value)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; string propertyName = &amp;quot;EmailAddress&amp;quot;;&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // Perform any validation here&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if (_EmailAddress != value)      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _EmailAddress = value;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified,       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; propertyName);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;Public Class Customer      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Inherits BOBase &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _CustomerId As Integer?      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property CustomerId() As Integer?       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _CustomerId       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Friend Set(ByVal value As Integer?)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;If _CustomerId Is Nothing OrElse _      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Not _CustomerId.Equals(value) Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim propertyName As String = &amp;quot;CustomerId&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Perform any validation&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If Not _CustomerId.Equals(value) Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _CustomerId = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified, propertyName)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&lt;/font&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _FirstName As String      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property FirstName() As String       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _FirstName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As String)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _FirstName Is Nothing OrElse _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _FirstName IsNot value Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim propertyName As String = &amp;quot;FirstName&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Perform any validation       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _FirstName IsNot value Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _FirstName = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; propertyName)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _LastName As String      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property LastName() As String       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As String)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _LastName Is Nothing OrElse _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName IsNot value Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim propertyName As String = &amp;quot;LastName&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Perform any validation       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _LastName IsNot value Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _LastName = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; propertyName)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#160;&amp;#160;&amp;#160; Private _EmailAddress As String      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Public Property EmailAddress() As String       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Return _EmailAddress       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Set(ByVal value As String)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _EmailAddress Is Nothing OrElse _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _EmailAddress IsNot value Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Dim propertyName As String = &amp;quot;EmailAddress&amp;quot;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;#39; Perform any validation       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; If _EmailAddress IsNot value Then       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _EmailAddress = value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; SetEntityState(EntityStateType.Modified, _       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; propertyName)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End If       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; End Set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; End Property       &lt;br /&gt;End Class&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The first if statement in each of the property procedures for the Customer class checks whether the current value is null or was changed. If the property is changed, you want to revalidate it, set it as modified, and generate a PropertyChanged event (which is handled in the SetEntityState method).&lt;/p&gt;  &lt;p&gt;NOTE: C# uses a != operator to judge whether the value was changed. VB cannot use the &amp;lt;&amp;gt; operator because VB propagates null values. So if either value is null (nothing) the result is false. (See &lt;a href="http://msdn.microsoft.com/en-us/library/0x9tb07z.aspx"&gt;this msdn entry&lt;/a&gt; for more information.) To prevent this problem, IsNot is used in the VB code to determine if the value was changed.&lt;/p&gt;  &lt;p&gt;The null check allows for possible validation of required fields (that is, fields that cannot be null or empty). If you know you will never need a null validation check, you can leave the null check off the first if statement.&lt;/p&gt;  &lt;p&gt;The propertyName variable defines a name&amp;#160; that you can use in any validation error messages and it is the name used in the PropertyChanged event.&lt;/p&gt;  &lt;p&gt;You can then perform any necessary validation. In this simple example, no validation was added. If you want to see an example of some validation, check out &lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/07/21/building-a-business-object-base-class.aspx"&gt;this post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Finally, if the value was changed, the backing variable is set to the new value and the SetEntityState method is called&amp;#160; to mark the business object as&amp;#160; &amp;quot;dirty&amp;quot; and to generate the PropertyChanged event.&lt;/p&gt;  &lt;h2&gt;Define the Testing Scenarios&lt;/h2&gt;  &lt;p&gt;So let&amp;#39;s start with the test of the LastName property. Looking at the requirements, the following testing scenarios are required:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Initial null value; set to null value (should perform validation but not set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial null value; set to valid&amp;#160; string (should perform validation and set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial null value; set to empty string (should perform validation and set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial string value; set to null value (should perform validation and set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial string value, set to different string value (should perform validation and set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial string value, set&amp;#160; to same string value (should not&amp;#160; perform validation and not set the dirty flag) &lt;/li&gt;    &lt;li&gt;Initial string value, set&amp;#160; to empty value (should perform validation and set the dirty flag) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And if you have validation code, you will have more scenarios to test valid and invalid values. But this is enough to give you the general idea.&lt;/p&gt;  &lt;p&gt;So now let&amp;#39;s generate the unit test for the LastName property using the tools provided in Visual Studio (Professional Edition or above).&lt;/p&gt;  &lt;h2&gt;Generate the Unit Test&lt;/h2&gt;  &lt;p&gt;The following are the steps for generating the unit test for a particular property procedure or method:&lt;/p&gt;  &lt;p&gt;1) Open the Code Editor for the code you want to test.&lt;/p&gt;  &lt;p&gt;2) Right-click and select Create Unit Tests... from the context menu.&lt;/p&gt;  &lt;p&gt;The following dialog will appear:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/7713.image_5F00_52563B2F.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6646.image_5F00_thumb_5F00_77DFB890.png" width="430" height="318" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;3) Select the properties, methods, or&amp;#160; constructors you wish to test.&lt;/p&gt;  &lt;p&gt;If you were in a specific property procedure or method, that procedure or method is automatically checked in this dialog. You can select to generate tests for any properties, methods,&amp;#160; or constructors using this dialog.&lt;/p&gt;  &lt;p&gt;Notice the Output project combobox on this dialog. Using this combobox, you can create a new C# unit test, new VB unit test, or select any existing unit test project if you already&amp;#160; have some in your solution. This allows you to add unit tests to existing unit testing projects at any point in the development process.&lt;/p&gt;  &lt;p&gt;4) Click OK.&lt;/p&gt;  &lt;p&gt;5) If you are creating a new C# or VB project, enter the project name and click Create.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/0385.image_5F00_4F60D67C.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/4274.image_5F00_thumb_5F00_2E6D63D5.png" width="416" height="136" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;6) The test project is then added to your Solution Explorer.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/5734.image_5F00_0D79F12E.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/deborahk.metablogapi/6327.image_5F00_thumb_5F00_3E992BCE.png" width="408" height="327" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you created a VB test project, the result is the same, but with a CustomerTest.vb file&amp;#160; within the BoTest project.&lt;/p&gt;  &lt;h2&gt;View the Generated Code&lt;/h2&gt;  &lt;p&gt;Visual Studio automatically creates an first cut of your unit testing code.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In C#:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Double-click on&amp;#160; CustomerTest.cs to view the code.&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;/// &amp;lt;summary&amp;gt;      &lt;br /&gt;///A test for LastName       &lt;br /&gt;///&amp;lt;/summary&amp;gt;       &lt;br /&gt;[TestMethod()]       &lt;br /&gt;public void LastNameTest()       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Customer target = new Customer(); // TODO: Initialize to an appropriate value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string expected = string.Empty; // TODO: Initialize to an appropriate value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string actual;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.Inconclusive(&amp;quot;Verify the correctness of this test method.&amp;quot;);       &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;In VB:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Double-click on CustomerTest.vb to view the code.&lt;/p&gt;  &lt;p&gt;&lt;font color="#65402e" face="Consolas"&gt;&amp;#39;&amp;#39;&amp;#39;&amp;lt;summary&amp;gt;      &lt;br /&gt;&amp;#39;&amp;#39;&amp;#39;A test for LastName       &lt;br /&gt;&amp;#39;&amp;#39;&amp;#39;&amp;lt;/summary&amp;gt;       &lt;br /&gt;&amp;lt;TestMethod()&amp;gt; _       &lt;br /&gt;Public Sub LastNameTest()       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim target As Customer = New Customer &amp;#39; TODO: Initialize to an appropriate value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim expected As String = String.Empty &amp;#39; TODO: Initialize to an appropriate value       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Dim actual As String       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; target.LastName = expected       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; actual = target.LastName       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.AreEqual(expected, actual)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Assert.Inconclusive(&amp;quot;Verify the correctness of this test method.&amp;quot;)       &lt;br /&gt;End Sub&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;The TestMethod attribute defines this method as a unit test. It is then picked up by the other unit testing tools within Visual Studio.&lt;/p&gt;  &lt;p&gt;The generated code includes some ToDo notes, defining where you should change the code.&lt;/p&gt;  &lt;p&gt;The Assert class is a key aspect of your unit tests. It provides many methods that you can use to assert whether your test produced expected results.&lt;/p&gt;  &lt;p&gt;The generated code uses two of the Assert class methods. The &lt;strong&gt;AreEqual&lt;/strong&gt; method determines whether the expected and actual values are equal. If not, it fails the test.&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;Inconclusive&lt;/strong&gt; method always causes the test to fail. This is added to all generated code to ensure that the test will fail until you modify the test with valid values.&lt;/p&gt;  &lt;p&gt;At this point, you can try to execute this unit test, or update it first and then execute it.&lt;/p&gt;  &lt;p&gt;See the following posts for more information:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-execution.aspx"&gt;Unit Testing: Execution&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/25/unit-testing-code-coverage.aspx"&gt;Unit Testing: Code Coverage&lt;/a&gt; (Visual Studio Team Editions ONLY) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-testing-properties.aspx"&gt;Unit Testing: Testing Properties&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-exposing-internal-friend-members.aspx"&gt;Unit Testing: Exposing Internal/Friend Members&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msmvps.com/blogs/deborahk/archive/2009/10/29/unit-testing-exposing-private-members.aspx"&gt;Unit Testing: Exposing Private Members&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1735139" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/deborahk/archive/tags/VB/default.aspx">VB</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/.NET/default.aspx">.NET</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/CSharp/default.aspx">CSharp</category><category domain="http://msmvps.com/blogs/deborahk/archive/tags/Testing/default.aspx">Testing</category></item></channel></rss>