<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/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>Adil Akhter's Weblogs : TestContext</title><link>http://weblogs.asp.net/adilakhter/archive/tags/TestContext/default.aspx</link><description>Tags: TestContext</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>More on Unit Testing : TestContext</title><link>http://weblogs.asp.net/adilakhter/archive/2008/05/04/more-on-unit-testing-testcontext.aspx</link><pubDate>Sun, 04 May 2008 10:24:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6156455</guid><dc:creator>Adil Akhter</dc:creator><author>Adil Akhter</author><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6156455</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6156455</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/05/04/more-on-unit-testing-testcontext.aspx#comments</comments><description>&lt;p&gt;&lt;font size="+0"&gt;&lt;font size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;font face="Arial"&gt;&lt;font size="5"&gt;I&lt;/font&gt;n Test Driven Development&amp;#160; as a developer we spend significant amount of time in writing unit tests. As improving coding coverage, testing all the boundary condition and ensuring the of quality code is significantly important, writing unit test effectively become one of the priority that we has to consider in software development. &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="+0"&gt;&lt;font size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font face="Arial" size="2"&gt;In our today's discussion, we will see what is TestContext of VSTS unit testing framework and how we can use TestContext&amp;#160; to leverage writing effective unit tests for our application.            &lt;br /&gt;            &lt;br /&gt;Prior to move forward with our today's Discussion on TestContext, I would really suggest you the following postings- &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;font size="+0"&gt;&lt;font size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;a href="http://weblogs.asp.net/adilakhter/archive/2008/04/18/why-unit-testing-is-so-important.aspx" target="_blank" mce_href="http://weblogs.asp.net/adilakhter/archive/2008/04/18/why-unit-testing-is-so-important.aspx"&gt;&lt;font face="Arial" color="#000000"&gt;Why unit testing is so important?&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;font size="2"&gt;&lt;a href="http://weblogs.asp.net/adilakhter/archive/2008/04/18/tdd-in-a-nutshell.aspx" target="_blank" mce_href="http://weblogs.asp.net/adilakhter/archive/2008/04/18/tdd-in-a-nutshell.aspx"&gt;&lt;font face="Arial" color="#000000"&gt;Test Driven Development in a Nutshell.&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;font face="Arial"&gt;So, let's begin with a brief description on what is TestContext. Then we will go through different scenarios where we can use TestContext. :)&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;&lt;span style="color: #2b91af"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#000000"&gt;&lt;font face="Arial" color="#000000" size="2"&gt;&lt;span style="color: #2b91af"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;&lt;font face="Arial"&gt;What is TestContext?&lt;/font&gt;&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;&lt;font color="#000000"&gt;&lt;font size="2"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #2b91af"&gt;TestContext &lt;/span&gt;is a abstract class of Microsoft.VisualStudio.TestTools.UnitTesting namespace that provides various information about the current test run. Purposes that has been served by TestContext Class - &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;1.&amp;#160; To store information and provide information to the unit tests during Unit Test Run.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;2.&amp;#160; Provide a mechanism to measure performance of your code being tested by the Unit Test.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;3.&amp;#160; In &lt;/font&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms243399(VS.80).aspx" target="_blank" mce_href="http://msdn2.microsoft.com/en-us/library/ms243399(VS.80).aspx"&gt;&lt;font face="Arial" color="#000000" size="2"&gt;Testing the web service&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial" size="2"&gt; it stores the additional information, like server's URL.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;4.&amp;#160; In &lt;/font&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms404696(VS.80).aspx" target="_blank" mce_href="http://msdn2.microsoft.com/en-us/library/ms404696(VS.80).aspx"&gt;&lt;font face="Arial" color="#000000" size="2"&gt;Asp.Net unit tests&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial" size="2"&gt;, it get holds of the Page object.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;5.&amp;#160; For &lt;/font&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms404708(VS.80).aspx" target="_blank" mce_href="http://msdn2.microsoft.com/en-us/library/ms404708(VS.80).aspx"&gt;&lt;font face="Arial" color="#000000" size="2"&gt;Data Driven Unit Tests&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial" size="2"&gt; , it provides access to the data rows.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial"&gt;The class definition of the TestContext Class -&lt;/font&gt;&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 88.48%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; height: 210px; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; TestContext&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;    {&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; AspNetDevelopmentServerPrefix = &lt;span style="color: #006080"&gt;&amp;quot;AspNetDevelopmentServer.&amp;quot;&lt;/span&gt;;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; TestContext();&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; UnitTestOutcome CurrentTestOutcome { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; DbConnection DataConnection { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; DataRow DataRow { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; IDictionary Properties { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; System.Web.UI.Page RequestedPage { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TestDeploymentDir { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TestDir { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TestLogsDir { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TestName { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddResultFile(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fileName);&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; BeginTimer(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; timerName);&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; EndTimer(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; timerName);&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; WriteLine(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; format, &lt;span style="color: #0000ff"&gt;params&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;[] args);&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;    }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;font face="Arial"&gt;To start with the TestContext , &lt;font color="#000000"&gt;we need to add a property in our Unit Test class as -&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/ClassDiagram1_4.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/ClassDiagram1_4.jpg"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="304" alt="ClassDiagram1" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/ClassDiagram1_thumb_1.jpg" width="402" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/ClassDiagram1_thumb_1.jpg" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt;&amp;#160;&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;font size="+0"&gt;&lt;font size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;strong&gt;Figure1: TestContext Property in Unit Test class&lt;/strong&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;font face="Arial" size="2"&gt;Now if we just add a simple test and debug it - we will find that the VSTS Unit Testing Framework actually using an instance of&amp;#160; &lt;strong&gt;UnitTestAdapterContext&lt;/strong&gt; which is derived from TestContext. This property TestContext is automatically initialized/assigned by the test run engine of VSTS when the Unit Test class is initialized after [ClassInitalize] method and before [TestInitalize] method.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1.png"&gt;&lt;font face="Arial" color="#000000"&gt;&lt;/font&gt;&lt;/a&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="319" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1_thumb.png" width="560" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1_thumb.png" /&gt;&lt;/a&gt;&lt;/a&gt;&lt;/a&gt;&lt;font face="Arial"&gt;&amp;#160; &lt;/font&gt;&lt;font size="2"&gt;&lt;font size="+0"&gt;&lt;font face="Arial" size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;strong&gt;Figure2 : UnitTestAdapterContext and its' properties in Debug Mode &lt;/strong&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;font size="+0"&gt;&lt;font face="Arial" size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;strong&gt;Want to know more about TestContext?&lt;/strong&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;It would be really hard to find the assembly&amp;#160; that contains UnitTestAdapterContext Class unless we search the private assemblies installed in &amp;lt;vs installation directory&amp;gt;\common7\IDE\PrivateAssemblies ; in my case which is &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;- C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies.The assembly that contains UnitTestAppterContextClass -&lt;em&gt;Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter.dll&lt;/em&gt;. &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;UnitTestAdapterContext class looks like following in reflector -&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_4.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_4.png"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="554" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb.png" width="485" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb.png" /&gt;&lt;/font&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure3 : UnitTestAdapterContext in Reflector&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;strong&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;&lt;strong&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;h4&gt;&lt;strong&gt;&lt;font face="Arial"&gt;How can we use TestContext ?&lt;/font&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Like I mentioned in the beginning , we can use TestContext in different cases writing unit tests. Now , we are going to look at some features of TestContext class that we can use very easily in our unit tests.&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 1 : &lt;/strong&gt;&lt;u&gt;Getting path of the folder that current test run created for storing input and outputs &lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;u&gt;&lt;/u&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;It's a really handy feature of TestContext. It provides you the path of the unique folder for current test run that VSTS unit testing framework creates in every test run. &lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;In VSTS unit testing framework, every test run create a unique folder in&amp;#160; machine where it's running the test and generate a xml based test report ( *.trx) -&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_6.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_6.png"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="169" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb_2.png" width="244" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb_2.png" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 4 : Folders/Directories that are created by Test Run 
      &lt;br /&gt;

      &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Additional input or output of unit test can be stored in this folder and also can be cleaned up before exiting the unit test(if required). Furthermore, it's the safest place to put the additional stuff related to unit tests because our application have full access to this folder ( just consider the situation where unit tests are running in a Build Machine or in a remote server where application might not have access to &amp;quot;C:\Temp\&amp;quot; folder :) ). &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;So, how can we get the path of the folder of current test run? Simple - &lt;/font&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;font face="Arial"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; testDirectory = TestContext.TestDir;&lt;/font&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;We can get access to the deployment folder&amp;#160; and the folder that contain logs&amp;#160; as well -&lt;/font&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;font face="Arial"&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;deploymentDirectory = TestContext.TestDeploymentDir;
&lt;span style="color: blue"&gt;string &lt;/span&gt;logDirectory = TestContext.TestLogsDir;&lt;/font&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 2 : &lt;/strong&gt;&lt;u&gt;Generating report how much time was elapsed to complete the Unit Tests&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;u&gt;&lt;/u&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;/em&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;TestContext Class has 2 public member &lt;strong&gt;BeginTimer&lt;/strong&gt; and &lt;strong&gt;EndTimer&lt;/strong&gt; which takes a string parameter as argument ( Name of the timer). Using this feature of TestContext class, how much time elapsed to run particular unit test can be measured very easily. This feature of TestContext might be useful in tracking how much time the code to be tested is consuming and whether or not it's going to meet speed criteria of nonfunctional requirements. &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;TestContext.BeginTimer(&lt;span class="str"&gt;&amp;quot;longRunningProcess&amp;quot;&lt;/span&gt;);&lt;/font&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;#160;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="rem"&gt;// Call the long running method here to test whether it meet the performance requirement&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="rem"&gt;//....&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="rem"&gt;//&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;#160;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;TestContext.EndTimer(&lt;span class="str"&gt;&amp;quot;longRunningProcess&amp;quot;&lt;/span&gt;);&lt;/font&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;          &lt;/font&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;font face="Arial"&gt;Result of the timer is shown as - &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_8.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_8.png"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="236" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb_3.png" width="348" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb_3.png" /&gt;&lt;/font&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 5: Output from the Timer &lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 3 : &lt;/strong&gt;&lt;u&gt;Adding additional information in Test Result&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;There is another cool property in the TestContext class which gives you flexibility to provide additional information in Test Result which will be stored in Test Result file( .trx extension stored as Xml). This could be really useful to provide additional information about the Test such as Test Environment, parameter and other details that might be important to store with test result. Lets consider a particular unit test - &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; [TestMethod]&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShouldCreateUser()&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; {&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// ... Unit Test Codes....&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; }&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; [TestCleanup]&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestCleanup()&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt; {&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     TestContext.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;{0} : {1}&amp;quot;&lt;/span&gt;, TestContext.TestName ,TestContext.CurrentTestOutcome);&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt; }&lt;/font&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Using &lt;strong&gt;TestContext.WriteLine&lt;/strong&gt; , we can provide additional information [ For Example - just to show, in the above example at line 10 , we are writing the test name and test result] and that is visible to the test result viewer as -&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/testoutput.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/testoutput.jpg"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="204" alt="testoutput" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/testoutput_thumb.jpg" width="320" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/testoutput_thumb.jpg" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 6: Output from TestContext.WriteLine 
      &lt;br /&gt;

      &lt;br /&gt;

      &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 4 : &lt;/strong&gt;&lt;u&gt;TestContext in Asp.Net Unit Testing&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;TestContext provides the access to the Asp.net Page object representing the current web request while unit testing Asp.net Web Application. How? TestContext has a property - RequestPage which is actually an instance of System.Web.UI.Page object and defined as- &lt;/font&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&amp;quot;...references the &lt;b&gt;Page&lt;/b&gt; object created by the URL used to invoke the test&amp;quot;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TestContextInAspnet.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TestContextInAspnet.jpg"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="251" alt="TestContextInAspnet" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TestContextInAspnet_thumb.jpg" width="482" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TestContextInAspnet_thumb.jpg" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 7: TestContext.RequestPage 
      &lt;br /&gt;

      &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;This property is only valid for Asp.Net Unit Testing. After getting hold of Page Object of current web request, any control of the page can be accessed using &lt;a href="http://msdn.microsoft.com/en-us/library/486wc64h.aspx" target="_blank" mce_href="http://msdn.microsoft.com/en-us/library/486wc64h.aspx"&gt;FindControl&lt;/a&gt; method of the Page Object. Using &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.privateobject(VS.80).aspx" target="_blank" mce_href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.privateobject(VS.80).aspx"&gt;PrivateObject&lt;/a&gt; class, we can invoke the private/protected methods of the current .Aspx page represented by Page Object.&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;
    &lt;br /&gt;Example of an Asp.net Unit Test :&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; [TestMethod]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; [HostType(&lt;span style="color: #006080"&gt;&amp;quot;Asp.Net&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; [UrlToTest(&lt;span style="color: #006080"&gt;&amp;quot;http://localhost/ourwebapplication&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestMethod()&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     Page page = TestContext.RequestedPage;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     PrivateObject privateObject = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PrivateObject(page);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     Button button = (Button)page.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;Button1&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;     privateObject.Invoke(&lt;span style="color: #006080"&gt;&amp;quot;Button1_Click&amp;quot;&lt;/span&gt;, button, EventArgs.Empty);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;     Label label = (Label)page.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;Label1&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;     Assert.AreEqual&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color: #006080"&gt;&amp;quot;Hello World !!!!&amp;quot;&lt;/span&gt;, label.Text);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;
  &lt;p class="Tahoma10" style="margin: 0px"&gt;
    &lt;br /&gt;We have a label and button in our an .aspx web page. When a button click event occurs, the label text get changed to &amp;quot;Hello world !!!&amp;quot;. And another important things to note that we are using IIS to host our web application(line 3).Now, we are going to test this feature using Asp.Net Unit Test in the sample code above. 

    &lt;br /&gt;&lt;/p&gt;

  &lt;p class="Tahoma10" style="margin: 0px" mce_keep="true"&gt;&amp;#160;&lt;/p&gt;
&lt;/font&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;So, first we get hold of our Page object(Line 6) representing our current web request(UrlToTest in Line 3) through the TestContext.RequestPage which eventually enable us to access any control of the page object(e.g. Line 10 &amp;amp; 13). Using the PrivateObject( line 8), we could conveniently invoke any member of the page class as well (line 11). 
    &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Hence, using TestContext, we can effective &lt;em&gt;leverage&lt;/em&gt; our codes inside Aspx page into Test5 Coverage.&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;
        &lt;br /&gt;Scenario 5: &lt;/strong&gt;&lt;u&gt;TestContext in Data Driven Unit Tests 
        &lt;br /&gt;

        &lt;br /&gt;&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;In Data Driven Unit Test, TestContext provides access to the current DataRow for which test is running and by that way, it provides access to every DataRow of the DataSource one by one. 
    &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;In the following example, we will see how the TestContext enable us to getting access to every DataRow in the DataSource - 
    &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;First, lets define our Table that contains few UserContacts with valid information. So, our unit test should create every one as a UserContact of our Application. But that's not our example's goal here. In this example , We will see how TestContext enables us to access every UserContact stored in the UserContact Table so easily.&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableDefinition.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableDefinition.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="177" alt="TableDefinition" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableDefinition_thumb.jpg" width="404" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableDefinition_thumb.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 7: UserContact Table Definition&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Let's put some Valid User Contact Information in our Table - UserContact -&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableData.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableData.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="120" alt="TableData" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableData_thumb.jpg" width="547" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableData_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 7: Data in UserContact Table 
      &lt;br /&gt;

      &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;After that, let's write our unit test -&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; [DataSource(&lt;span style="color: #006080"&gt;&amp;quot;System.Data.SqlClient&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;[path to MDF]\&amp;quot;;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; Integrated Security=True;User Instance=True&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;UserContact&amp;quot;&lt;/span&gt;, &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; DataAccessMethod.Sequential), TestMethod()]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShouldCreateUsers()&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; { &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userLoginName = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;LoginName&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userFirstName = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userLastName = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;LastName&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userEmailAddress = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;EmailAddress&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userDepartment = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;Department&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;     TestContext.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Creating user - Login Name :{0} Name : {1} {2} &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;                           EmailAddress : {3} &amp;quot;&lt;/span&gt;, userLoginName, userFirstName, &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;                           userLastName, userEmailAddress);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; successful = UserManger.CreateUser(userLoginName, &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;                                           userFirstName, userLastName, &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;                                           userEmailAddress, userDepartment);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;     Assert.IsTrue(successful);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/div&gt;

&lt;div&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/div&gt;

&lt;div&gt;&lt;font face="Arial"&gt;From the above example, we can see that (line 5&amp;#160; - 10 ) , TestContext is providing us access to the current DataRow for which the unit test is getting executed. We can see the output of TestContext.Writeline(line 12) and Result of the unit test for each DataRow below -&lt;/font&gt;&lt;/div&gt;

&lt;div&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/div&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 6: &lt;/strong&gt;&lt;u&gt;TestContext.AddResultFile&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;Last but not the least, TestContext has another useful member called AddResultFile which is defined as - &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;AddResultFile(&lt;span style="color: blue"&gt;string &lt;/span&gt;filename)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;Through TestContext.AddResulFile, additional files can be added with the test result. The additional file will be stored in the unique folder created for current test run.This might be useful in some cases, for example, if we are validating our objects with some external resource, like schema - we can store the schema with our test result so that we can validate our test result later on after test run. &lt;/p&gt;

&lt;h4&gt;Conclusion&lt;/h4&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Hence, we can utilize the TestContext class in several cases to solve our problem in writing unit tests. But saying all this, I would like to emphasize on designing test cases and map it to a unit test carefully because &amp;quot;&lt;em&gt;Harnessing the power that is provided by the tool and utilizing it &lt;strong&gt;effectively&lt;/strong&gt; and every possible way&lt;/em&gt;&amp;quot; could only bring desirable result .&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font size="2"&gt;In our today's discussion, we went through several scenarios where we can leverage TestContext to write a better and precisely more effective unit test using the Unit Testing Framework provided with Visual Studio. Thanks for being with me so far and I would really appreciate comments or any suggestion. 
    &lt;br /&gt;&lt;/font&gt;&lt;font face="Arial"&gt;
    &lt;br /&gt;I would really appreciate any comments or suggestion on this topic. &lt;/font&gt;&lt;font face="Arial"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fadilakhter%2farchive%2f2008%2f05%2f04%2fmore-on-unit-testing-testcontext.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fadilakhter%2farchive%2f2008%2f05%2f04%2fmore-on-unit-testing-testcontext.aspx" border="0" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6156455" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/adilakhter/archive/tags/TDD/default.aspx">TDD</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/TestContext/default.aspx">TestContext</category></item></channel></rss>