<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gabriel Iglesias</title>
	<atom:link href="http://blogs.southworks.net/giglesias/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.southworks.net/giglesias</link>
	<description>Just another Southworks site</description>
	<lastBuildDate>Fri, 31 Aug 2012 15:29:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Tips and recommended practices for handling exceptions and validations in .NET C#</title>
		<link>http://blogs.southworks.net/giglesias/2012/08/31/tips-and-recommended-practices-for-handling-exceptions-and-validations-in-net-c/</link>
		<comments>http://blogs.southworks.net/giglesias/2012/08/31/tips-and-recommended-practices-for-handling-exceptions-and-validations-in-net-c/#comments</comments>
		<pubDate>Fri, 31 Aug 2012 15:08:11 +0000</pubDate>
		<dc:creator>giglesias</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Exceptions Handling]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/giglesias/?p=169</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/giglesias/2012/08/31/tips-and-recommended-practices-for-handling-exceptions-and-validations-in-net-c/" class="more-link">read more<img src="http://blogs.southworks.net/giglesias/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>This time I wanted to show the research we made with my colleague <a href="http://davefrassoni.com"><strong>David Frassoni</strong></a> about recommendations and tips when handling exceptions and validations in C#.</p>
<h2>When to Throw an Exception</h2>
<p>We should not throw exceptions for every erroneous event. For example in an application in which we want to get a list of students, and there are no students matching with the user’s search, we should not throw a custom exception (e.g.: NoStudentsFoundException), because it’s not actually wrong. In this case it’s recommended to return a state value (e.g.: an empty students list or “null”).</p>
<p>When throwing an exception, don’t use “throw new Exception()”, it’s too generic. We should use the most accurate exception possible according to the operation we are handling.</p>
<p>When throwing an exception in a <strong>catch</strong> statement, we should append the Inner Exception to keep track of the initial cause.</p>
<p>There are situations where is not recommended to append the Inner Exceptions. For example, in a multi-layer application, if an exception occurs while performing a specific query to the database, if we re-throw the exception through the entire application until we reach the UI layer, we can expose sensitive information to the user. It’s important to be aware of this and know when to stop handling the Inner Exception through layers, and expose to the user a clear message of the exception, without sensitive information. We will talk about this later in this post.</p>
<h2>Handling Multiple Exceptions Type</h2>
<p>In case we need to handle each different exception in a different way, we should use one single <strong>try</strong> with several <strong>catch</strong> statements below it, one for each different type of exception that may occur in the code within the try. Also the catch statements should be placed in order, from the most specific to the most generic one, to handle the specific exception before it is passed to a more general catch block. The <strong>finally</strong> statement should be used to de-allocate resources, if applies.</p>
<h2>Data Validation</h2>
<p>To avoid unnecessary exception handlings, external data should be <strong>always</strong> checked before operating with it, even if it was a file that we’ve just written, or properties we’ve just received from a form. We should never trust anything coming from outside our application. Sometime, as we may use that information to hit a data source, they can contain unexpected code that can harm it, or even delete it.</p>
<h2>Disposing Objects Properly</h2>
<p>We should use the <strong>using</strong> statement in as many places as we can in our code, when we are dealing with Disposable objects. This way we prevent resource leaks even in the presence of an exception.</p>
<h2>Validating vs Throwing Exceptions</h2>
<p>There are some situations where it’s better to programmatically check for a condition in a block instead of catching an exception that eventually would be thrown. We can simply use an <strong>if</strong> statement to check if a condition matches a proper state, and then do something, instead of catching the exception that will be caused if not using the if statement. The fact that allows us to choose one or the other method is how often we expect this event to occur:</p>
<ul>
<li>If the event occurs in exceptional cases, use exception handling with <strong>try/catch/finally</strong> statements. This way is better than programmatically check the condition because less code is needed in the success case.</li>
<li>If the event occurs often, use programmatic checks. This way is better than handling the exception because that will require more processing effort.</li>
</ul>
<h2>Atomicity</h2>
<p>After an exception handling, we should check that we came back into a valid state, and no undesired effects occurred as a consequence of the exception. For example, if working with a transaction to a database, ensure that the atomicity principle is applied.</p>
<h2>Custom Exceptions</h2>
<p>We can create a custom exception when the exception types given by .NET Framework do not fit our needs. When creating custom Exceptions:</p>
<ul>
<li>Define new exception types only for programmatic scenarios.</li>
<li>Inherit from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value.</li>
</ul>
<h2>Exception Messages Format &amp; Logging</h2>
<p>Messages thrown in exceptions should be grammatically correct, concise about the problem and end with a period.</p>
<p>We should always log the exceptions the application throws. When doing this, we should log Exception.ToString(), not only Exception.Message, because this way we can obtain the stack trace, the inner exception and the message.</p>
<h3>Handling exceptions within different layers</h3>
<p>In most common applications with an infrastructure layer, a business layer and a high-level layer, there are some recommendations to perform a good exceptions handling:</p>
<p>In the Infrastructure layer, lots of exceptions throws are performed, because it deals with the data sources, and it’s more prone to exceptions. At this level, there are practically no catching operations.</p>
<p>As regards the business layer, it serves more for validations and filtering of exceptions messages. Here is where we should resolve all the business requirements, validating programmatically our code blocks. We should catch exceptions coming from the infrastructure layer here for not exposing sensitive information in exceptions messages to the high-level layer.</p>
<p>Finally, in the high-level one, we will perform mainly catches to handle exceptions coming from the infrastructure or business layer. At this point, no exceptions should be thrown, because we only have to show the information to the user. If an error occurs, we should warn the user about it in a friendly message.</p>
<p>There are some frameworks and libraries you can use to deal with exceptions. Some of them are:</p>
<ul>
<li><a href="http://www.microsoft.com/en-us/download/details.aspx?id=3102">Microsoft Enterprise Instrumentation Framework</a></li>
<li><a href="http://logging.apache.org/log4net/">Apache log4net</a></li>
<li><a href="http://entlib.codeplex.com/">Microsoft Enterprise Library</a></li>
<li><a href="http://code.google.com/p/elmah/">ELMAH (Error Logging Modules and Handlers)</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/aaaxk5bx%28VS.71%29.aspx">System Monitoring Components</a></li>
</ul>
<h3>Sources</h3>
<div>
<div>
<ul>
<li><a href="http://www.codeproject.com/Articles/9538/Exception-Handling-Best-Practices-in-NET#Don%27treinventthewheel25">http://www.codeproject.com/Articles/9538/Exception-Handling-Best-Practices-in-NET#Don%27treinventthewheel25</a></li>
<li><a href="http://stackoverflow.com/questions/86766/how-to-properly-handle-exceptions-when-performing-file-io">http://stackoverflow.com/questions/86766/how-to-properly-handle-exceptions-when-performing-file-io</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/seyhszts.aspx">http://msdn.microsoft.com/en-us/library/seyhszts.aspx</a></li>
<li><a href="http://www.dreamincode.net/forums/topic/177003-discussion-exception-handling-in-c%23/">http://www.dreamincode.net/forums/topic/177003-discussion-exception-handling-in-c%23/</a></li>
<li><a href="http://nedbatchelder.com/text/exceptions-in-the-rainforest.html">http://nedbatchelder.com/text/exceptions-in-the-rainforest.html</a></li>
</ul>
</div>
</div>
<p>Thanks to <a href="http://twitter.com/meydacjean"><strong>Hernan Meydac Jean</strong></a> and <a href="http://blogs.southworks.net/jrowies"><strong>Jorge Rowies</strong></a> for their contribution on this post!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Performance and Load Tests with Visual Studio 2010</title>
		<link>http://blogs.southworks.net/giglesias/2012/08/01/web-performance-and-load-tests-with-visual-studio-2010/</link>
		<comments>http://blogs.southworks.net/giglesias/2012/08/01/web-performance-and-load-tests-with-visual-studio-2010/#comments</comments>
		<pubDate>Wed, 01 Aug 2012 14:33:16 +0000</pubDate>
		<dc:creator>giglesias</dc:creator>
				<category><![CDATA[Load Tests]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Web Performance Tests]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/giglesias/2012/08/01/web-performance-and-load-tests-with-visual-studio-2010/</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/giglesias/2012/08/01/web-performance-and-load-tests-with-visual-studio-2010/" class="more-link">read more<img src="http://blogs.southworks.net/giglesias/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>Recently I’ve been working with Web Performance and Load Tests in Visual Studio 2010, with the objective of measuring some metrics of a web site, like the average page time and the average first byte time. To do this, I had to record several web tests to serve as the input of the Load test, which will finally show the metrics we want to measure. In this case, the web tests are based on the System Test Cases developed for this web site, but they also could be based on the use cases in a case where the test cases are more granular.</p>
<p>In a first section in this post, we will see how to easily capture the web requests of a test case using Fiddler, and then export them as Visual Studio Web Tests, so we can manipulate their settings, such as Request Timeout, Credentials, etc., using Visual Studio.</p>
<p>In a second section, we will see how to create a Load Test from the scratch using Visual Studio and feed it with the web tests already recorded, how we can easily manipulate its properties, how to execute it focusing on counters such as Average Page Time and Average First Byte Time and how to interpret the results obtained.</p>
<h2><span style="font-size: large"><strong>Prerequisites</strong></span></h2>
<ul>
<li><a href="http://www.fiddler2.com/fiddler2/">Fiddler Web Debugger</a>
<li>Visual Studio 2010 Ultimate
<li><a href="http://msdn.microsoft.com/en-us/library/dd648127.aspx">A Test Rig (Controller and Agents) properly configured to run Load Tests</a> </li>
</ul>
<h1><span style="font-size: small"><span></span></span></h1>
<p><strong><br /></strong></p>
<h1><strong><span style="font-size: x-large"><strong>Section 1 – Web Performance Tests</strong></span></strong></h1>
<p><strong></strong></p>
<p><strong></strong><br /><span style="font-size: medium"><strong>Recording Web Performance Tests using Fiddler</strong></span><br />Once Fiddler is opened and before recording any request, we will ensure that it’s capturing the Web traffic by checking the <em>Capturing</em> message at the bottom left corner of the window.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image_thumb.png" width="660" height="376"></a></p>
<p>Now, we are ready to start recording all the web requests of a Test Case. Open a browser, and log in to your web site (with your credentials if necessary).</p>
<p>Once in it, follow the flow of the test case that you want to record. When finished, go back to Fiddler and you will see all the web requests recorded.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image4.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image_thumb3.png" width="661" height="376"></a></p>
<p>Click <em>Capturing</em> at the bottom left corner of the window to stop capturing the web traffic. You will notice that the label <em>Capturing</em> disappears.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image6.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image6_thumb.png" width="402" height="122"></a></p>
<p>Now that we have our requests recorded, we will proceed to export them as Visual Studio Web Tests to open them in Visual Studio and manipulate their properties. To do this, go to <strong>File | Export Sessions | All Sessions</strong>. A new window will open to select the Export Format.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image5.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image_thumb4.png" width="656" height="373"></a></p>
<p>In the dropdown list, select <strong>Visual Studio Web Test</strong> and click <strong>Next</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image12.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image12_thumb.png" width="390" height="163"></a></p>
<p>After that, you will be requested to select the folder where you want the web test to be saved and to provide a name for it.</p>
<p>Finally, you have your web test ready to be included in your Test Project in Visual Studio.</p>
<h2><strong><span style="font-size: medium"><strong>Manipulating Web Tests in Visual Studio</strong></span></strong></h2>
<p>The next step will be to modify some properties of the web test already recorded with Fiddler, so it’s ready to be executed, using Visual Studio. In this case, we will focus on modifying the Timeout property of all the requests in the web tests to match a Performance Requirement of 4 seconds, and then we will add the necessary credentials for the requests to properly access the web site.</p>
<p>First, we will include the new web test to our Test Project in Visual Studio. To do this, right click your test project in Visual Studio and select <strong>Add | Existing Item</strong>. Browse to your .webtest file and click <strong>Add</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image15.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image15_thumb.png" width="551" height="396"></a></p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image18.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image18_thumb.png" width="528" height="366"></a></p>
<p>The web test is added to the project.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image211.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image21_thumb1.png" width="261" height="196"></a></p>
<p>Double-click the Web Test that you have already added. You will see the list of recorded requests performed in Fiddler.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image7.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image_thumb5.png" width="319" height="131"></a></p>
<h2><span style="font-size: medium"><strong>Editing the Timeout property</strong></span></h2>
<p>In the web test tree, right click the first request and select <strong>Properties</strong>. All the properties for that request will be displayed, and among them we will see the <strong>Timeout</strong>, which is the one we will modify to match the Performance Requirements.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image8.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image_thumb6.png" width="463" height="270"></a></p>
<p>In the Timeout option, insert the required amount of seconds (in this case, 4).</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image33.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image33_thumb.png" width="225" height="303"></a></p>
<p>Now, do the same for all the other requests.</p>
<blockquote><p><strong>Note:</strong> To speed up this process of modifying the Timeout for each request, you can press <strong>CTRL + H</strong> to open the “Find and Replace” dialog, and replace each Timeout=”60” for Timeout=”4” in the entire solution.</p>
</blockquote>
<blockquote><p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image27.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image27_thumb.png" width="271" height="218"></a></p>
</blockquote>
<h2><span style="font-size: medium"><strong>Adding Credentials</strong></span></h2>
<p>The last thing to do will be to add the credentials for the web test. To do this, click <strong>Set Credentials</strong> in the web test Menu.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image10.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image_thumb7.png" width="326" height="134"></a></p>
<p>Now, insert the <strong>Name</strong> and <strong>Password</strong> used when recording the test in Fiddler and click <strong>OK</strong>. Save the web test.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image39.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image39_thumb.png" width="348" height="125"></a></p>
<p>Finally, the web test is ready to be executed.</p>
<h2><span style="font-size: medium"><strong>Updating the Site URL</strong></span></h2>
<p>In case you have to update all your web tests because the URL of the site under test has changed, you can simply press <strong>CTRL + H</strong>, and replace all the old URLs with the new one.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image1.png"><img style="border-bottom: 0px;border-left: 0px;margin: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image_thumb1.png" width="244" height="195"></a></p>
<blockquote><p><strong>Note:</strong> some web tests can fail if the data used to execute the test wasn’t previously uploaded to the site in the test initialization.</p>
</blockquote>
<h2><span style="font-size: medium"><strong>Executing a Web Test</strong></span></h2>
<p>In order to execute the web test, click <strong>Run Test</strong> in the web test Menu.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image11.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image_thumb8.png" width="321" height="132"></a></p>
<p>Verify that the web test executed successfully. You can check some information about the test execution (Request Time is one of the important metrics).</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/SNAGHTML12a0f0.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="SNAGHTML12a0f0" src="http://blogs.southworks.net/giglesias/files/2012/08/SNAGHTML12a0f0_thumb.png" width="698" height="154"></a></p>
<p><strong><br /></strong></p>
<h1><strong><span style="font-size: x-large"><strong>Section 2 – Load Tests</strong></span></strong></h1>
<p><strong></strong></p>
<p><strong></strong></p>
<h2><span style="font-size: medium"><strong>Creating a New Load Test</strong></span></h2>
<p>In order to create a new Load Test, right-click your test project and select <strong>Add | New Test</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image51.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image51_thumb.png" width="640" height="480"></a></p>
<p>In the <strong>Add New Test</strong> window, select <strong>Load Test</strong>, provide a name for it and then click <strong>OK</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image54.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image54_thumb.png" width="462" height="391"></a></p>
<p>After that, a wizard will be displayed, where you will configure your load test. Click <strong>Next</strong> in the <strong>Welcome</strong> section.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image57.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image57_thumb.png" width="522" height="362"></a></p>
<p>The next step will be to configure the scenario where the load test will be executed. You will be requested to insert a name for the scenario and the Think time profile that you want to use. Provide a name, leave the think time profile by default to use the recorded think times in the requests and click <strong>Next</strong>.</p>
<blockquote><p><strong>Note:</strong> <em>Think time</em> is the time spent by a user perusing a Web page, including viewing the page and determining the next action. Think time does not include the time that is required for a page to load.</p>
</blockquote>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image60.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image60_thumb.png" width="531" height="369"></a></p>
<p>In the <strong>Load Pattern</strong> step, we will have to specify if we want a constant load of users during all the simulation, or if we want to increase the amount of users in steps. The difference between both of them is the duration of the simulation.</p>
<p>By choosing the first one, we should specify a warm up time for the load test, until the user count reaches the inserted value. This will cause the whole simulation to last less time than the one with a step load, because the amount of users will increase lineally until the maximum specified count, with no major complications for the processor of the machine that is executing the test.</p>
<p>By choosing the second one, we will have to specify the start user count, the step duration, the step user count and the maximum user count values. In this case, the duration of the simulation will have to be bigger than the other one, because if we choose a big amount of users per step, the processor of the machine that is executing the tests can start to fail, and the simulation results could not be entirely correct. We also should specify a short warm-up time at the beginning until the start user count is reached.</p>
<blockquote><p><strong>Note:</strong> When you specify a warm-up time, you avoid over stressing your site by having hundreds of new user sessions hitting the site at the same time. Also, the results obtained during this time will not be taken into account for the final results.</p>
</blockquote>
<p>After choosing the load pattern, click <strong>Next</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image63.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image63_thumb.png" width="528" height="366"></a></p>
<p>The next thing to do will be to choose the <strong>Test Mix Model</strong> that we want to use during the execution of the load test. This model specifies the probability of a virtual user running a given test in a load test scenario. This lets you simulate load more realistically.</p>
<p>Choose the <strong>Based on the total number of tests</strong> mix model, so we can select the distribution for each web test that we want to run in the load test in the next step, and click <strong>Next</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image66.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image66_thumb.png" width="532" height="369"></a></p>
<p>In the <strong>Test Mix</strong> section we will be able to add the web tests that the load test will use in the simulation to hit the web site. Also we will choose the distribution of the web tests, to indicate which ones we want to occur more times than others.</p>
<p>To add the web tests, click <strong>Add</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image69.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image69_thumb.png" width="535" height="371"></a></p>
<p>In the <strong>Add Tests window</strong>, choose the web tests included in the current project that you want to be executed during the simulation and press <strong>&gt;</strong>. Click <strong>OK</strong> to close the Add Tests window.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image72.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image72_thumb.png" width="429" height="328"></a></p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image75.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image75_thumb.png" width="429" height="327"></a></p>
<p>Back in the Test Mix section, choose the distribution for each web test and click <strong>Next</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image78.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image78_thumb.png" width="549" height="381"></a></p>
<p>The next step will be to choose the <strong>Network Mix</strong>, which is a combination of two factors: the selection of networks that are contained within the scenario, and the distribution of those networks within the scenario.</p>
<p>Add the networks that you would like the load test to mix, select their distribution and click <strong>Next</strong>. By default, we will only use <strong>LAN</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image81.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image81_thumb.png" width="550" height="382"></a></p>
<p>Another thing to specify is the <strong>Browser mix</strong>. This let us send the requests through different types and versions of browsers. We can add all the browsers that we want the load test to use and their distribution. By default, we will only use <strong>Internet Explorer 9.0</strong>. After selecting it, click <strong>Next</strong>.</p>
<blockquote><p><strong>Note:</strong> you will notice that Internet Explorer 9.0 is not loaded by default in Visual Studio. In order to add other browsers to test, take a look at this <a href="http://davefancher.com/2011/05/18/vsts-2010-load-test-browser-definitions/">article</a>.</p>
</blockquote>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image84.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image84_thumb.png" width="555" height="385"></a></p>
<p>In the <strong>Counter Sets</strong> section, we will add the controller computer and agents that will execute all the web tests in the load test. These ones will be available according to the configuration of the Test Rig that is required to execute Load Tests. In this case, we choose only one agent (which is the only one configured in the machine). Click <strong>Next</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image87.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image87_thumb.png" width="557" height="386"></a></p>
<p>The final step in the creation of a Load Test is to specify the <strong>Run Settings</strong>. You will be able to choose between <strong>Load test duration</strong>, where a <em>warm-up time</em> and a <em>run duration</em> will be required, and <strong>Test iterations</strong>, where you can select the number of times to run the test. By default, we will choose <strong>Load test duration</strong>. Provide a long warm-up time if you have chosen a constant load of users in the <strong>Load Pattern</strong> section of the wizard, or a short warm-up time if you have chosen a Step load of users. After providing also the duration time, click <strong>Finish</strong>.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image90.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image90_thumb.png" width="559" height="388"></a></p>
<p>Our Load Test is finished and added to our test project. Now we are ready to execute it.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image93.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image93_thumb.png" width="227" height="403"></a></p>
<p>The recommendation for a proper simulation is to choose a constant load of users (the maximum available in Visual Studio is 250 without license, and packages of 1000 users per license), a long warm-up time until the maximum specified amount of users is reached, and almost 15 minutes of simulation with the system stressed with the maximum load.</p>
<h2><span style="font-size: medium"><strong>Manipulating Load Tests in Visual Studio</strong></span></h2>
<p>Once we have our load test created, we can take a look at its properties, and modify them as we wish. This is useful to, for example, edit the total duration of the simulation, edit the warm-up time, add new web tests to the Test Mix, select Initialize tests and Terminate Tests, etc.</p>
<p><strong>Updating the Scenario</strong></p>
<p>In the load test tree, right-click the scenario and select <strong>Properties</strong>. The Properties pane should display.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image96.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image96_thumb.png" width="437" height="361"></a></p>
<p>Select <strong>Test Mix Type </strong>and click the <strong>Ellipsis</strong> next to the text mix type. The <strong>Edit Test Mix</strong> window should appear.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image99.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image99_thumb.png" width="439" height="325"></a></p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image102.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image102_thumb.png" width="438" height="366"></a></p>
<p>Here we can change the text mix model by selecting one of them in the dropdown list, add more web tests to our set by clicking <strong>Add</strong>, and also change their distribution.</p>
<blockquote><p><strong>Note:</strong> an alternative way to add new web tests to the test mix is by right-clicking <strong>Test Mix</strong> under the scenario in the load test tree, and selecting <strong>Add Tests</strong>. Analogously, the same can be done to add more browsers to the <strong>Browser Mix</strong>, or networks to the <strong>Network Mix</strong>.</p>
</blockquote>
<blockquote><p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image105.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image105_thumb.png" width="317" height="367"></a></p>
</blockquote>
<p>Apart from that, we can set an <strong>Initialize test</strong> and a <strong>Terminate test</strong> for all the web tests in the list. This means that before every web test that a user will execute in the simulation, the Initialize test will execute, and after the execution of all the web tests, the Terminate test will do so.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image108.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image108_thumb.png" width="398" height="332"></a></p>
<p>At the beginning we thought that this could be a good way to initialize the environment where we were working on in order to isolate the tests execution, but then we found a disadvantage that forced us to discard it:</p>
<ul>
<li><strong>Only one web test can be selected to run as Initialize test</strong> </li>
</ul>
<p>What we really needed was to execute several web tests to initialize the environment before the execution of each web test in the load test.</p>
<p>Finally, another thing to consider is that we can change the Load Pattern from the load test tree. Just right-click the load pattern and select <strong>Properties</strong>. Here you can select the pattern you want from the dropdown list, and also manage its properties.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image111.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image111_thumb.png" width="432" height="359"></a></p>
<p><strong>Updating the Run Settings</strong></p>
<p>In the Run Settings section, you can basically edit the duration of the simulation and the warm-up time, among other things. Right-click the <strong>Run Settings</strong> in the load test tree and select <strong>Properties</strong>. You will be able to edit them in that pane.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image114.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image114_thumb.png" width="433" height="458"></a></p>
<h2><span style="font-size: medium"><strong>Executing a Load Test</strong></span></h2>
<p>Now it’s time to execute our load test. To do so, click <strong>Run Test</strong> in the load test Menu.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image117.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image117_thumb.png" width="260" height="146"></a></p>
<p>The test will start to run, showing different graphs with the progress of the simulation. Those graphs show the current selected counters (you can find them in the <strong>Counters</strong> pane at the left side of the screen after expanding the nodes), such as <strong>User Load</strong>, <strong>Pages/Sec</strong>, <strong>Avg. Page Time</strong>, etc.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image120.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image120_thumb.png" width="1005" height="659"></a></p>
<p>An important thing to mention is that all the counters offered by Visual Studio are recorded during the simulation. We choose only the ones we need to show in the graphs, tables, etc., but we can also add new ones to the report after the simulation is finished.</p>
<h2><span style="font-size: medium"><strong>Interpreting Load Test results</strong></span></h2>
<p>When the load test finishes, all the results are stored in the database, and Visual Studio generates a general report. In this section, we will review most of the important things on it.</p>
<p><strong>Summary View</strong></p>
<p>Once the results are stored in the database, a Summary of the simulation is displayed.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image2.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image_thumb2.png" width="566" height="484"></a></p>
<p>An important section in this summary is the <strong>Overall Results</strong>, where some of the important counters are displayed. You can check the other ones in the <strong>Tables</strong> view.</p>
<blockquote><p><strong>Note:</strong> you can change the layout of the reports in the Load test menu. The different views are <strong>Summary</strong>, <strong>Graphs</strong> and <strong>Tables</strong>.</p>
</blockquote>
<blockquote><p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image126.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image126_thumb.png" width="541" height="52"></a></p>
</blockquote>
<p><strong>Graphs View</strong></p>
<p>In this view, you can select the graphs that you want to display. The tables below them will update automatically.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image129.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image129_thumb.png" width="1007" height="668"></a></p>
<p>The <strong>Key Indicators</strong> graph shows the behavior of the selected counters for this simulation, and it shows metrics such as minimums, maximums and average of each counter. If you compare this graph with the one shown in the <strong>Executing a Load Test </strong>section of this post, you will notice that the results obtained during the warm-up time (5 minutes) were removed.</p>
<blockquote><p><strong>Note:</strong> the Range column in the Key Indicators table shows the axis range of that counter in the graph.</p>
</blockquote>
<p><strong>Counters</strong></p>
<ul>
<li><strong>Pages/Sec:</strong> it measures the hard page faults per second. A hard page fault occurs when a memory page is not in the immediate memory and needs to be fetched from the disk.
<li><strong>Avg. Page Time:</strong> is a measure of the average time to download the page and all of its dependent requests, such as images, css, js, etc.
<li><strong>Avg. Response Time:</strong> is a measure of the average time that took to give a response after a request.
<li><strong>Avg. First Byte Time:</strong> is a measure of the average time that took to start receiving data back from the server. </li>
</ul>
<blockquote><p><strong>Note:</strong> the Average First Byte Time is not displayed by default. To display this counter in the table and the graph (as shown in Figure 41), you have to expand the <strong>Overall</strong> node in the <strong>Counters</strong> section at the left side of the screen, then expand the <strong>Request</strong> node, and then double-click <strong>Avg. First Byte Time</strong>.</p>
</blockquote>
<blockquote><p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image132.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image132_thumb.png" width="187" height="372"></a></p>
</blockquote>
<p>The <strong>Controller and Agents</strong> graph shows the performance of the processor and the memory of the machine that is executing the load test. This is an important thing to consider, because if the processor starts to fail more often, the metrics showed in the <strong>Key Indicators</strong> graph are not entirely correct. So, this indicates the time where the simulation performed correctly, and the time where the results are not entirely reliable (if the processor failed during a considerable time). When giving a report, we should only consider the first case.</p>
<p><strong>Tables View</strong></p>
<p>Finally, you can check the errors and the statistics of how many times each web test failed or passed within the execution of the load test in the <strong>Tables</strong> view. By following the links of the failures, you will get more information about the errors.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/08/image135.png"><img style="border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px" border="0" alt="image" src="http://blogs.southworks.net/giglesias/files/2012/08/image135_thumb.png" width="784" height="436"></a></p>
<h1><span style="font-size: large"><strong>Sources</strong></span></h1>
<ul>
<li><a href="http://blogs.msdn.com/b/jimblizzard/archive/2011/05/18/how-to-visual-studio-web-performance-tests-not-using-internet-explorer.aspx">How to: Visual Studio web performance tests – not using Internet Explorer</a>
<li><a href="http://msdn.microsoft.com/en-us/library/ms182572.aspx">How to: Create a New Load Test Using the New Load Test Wizard</a>
<li><a href="http://msdn.microsoft.com/en-us/library/ms243155.aspx">Configuring Test Controllers and Test Agents for Load Testing</a>
<li><a href="http://msdn.microsoft.com/en-us/library/ms182580.aspx">How to: Create Run Settings in the New Load Test Wizard</a>
<li><a href="http://msdn.microsoft.com/en-us/library/ms404664(v=vs.100).aspx">Considerations for Load Tests</a>
<li><a href="http://msdn.microsoft.com/en-us/library/ff406977.aspx">How to: Edit the Text Mix Model Using the Load Test Editor</a> (to add Initialize and Terminate tests) </li>
</ul>
<p>I hope you can find all of this useful!</p>
<p>Thanks!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to run MSTest in a MSBuild script</title>
		<link>http://blogs.southworks.net/giglesias/2012/07/02/how-to-run-mstest-in-a-msbuild-script/</link>
		<comments>http://blogs.southworks.net/giglesias/2012/07/02/how-to-run-mstest-in-a-msbuild-script/#comments</comments>
		<pubDate>Mon, 02 Jul 2012 15:53:58 +0000</pubDate>
		<dc:creator>giglesias</dc:creator>
				<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[TeamCity7]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/giglesias/?p=45</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/giglesias/2012/07/02/how-to-run-mstest-in-a-msbuild-script/" class="more-link">read more<img src="http://blogs.southworks.net/giglesias/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>I would like to show how to run MSTest in a single MSBuild script. Basically what I did is to execute MSTest.exe and pass the test assemblies and the test settings via command line. You should always include the test settings file because it tells if the Code Coverage is enabled, and in which assemblies.</p>
<p>First of all, in our build script, we have to specify the path to MSTest.exe. We will then create a new target in our build script where we will execute the tests.</p>
<p><strong>NOTE</strong>: Ensure to put this target after compilation so the test assemblies are generated.</p>
<p>To pass the test assemblies and the test settings to MSTest.exe, we will use the /testcontainer and /testsettings command line options respectively. If you want to include several test assemblies, you have to put as many /testcontainer as assemblies you have. Here is an example:</p>
<p>&lt;Target Name=&#8221;RunTests&#8221; DependsOnTargets=&#8221;Compilation&#8221;&gt;</p>
<blockquote><p><strong>&lt;Exec</strong> Command=&#8221;<strong>&amp;quot;$(MSTestPath)\MSTest.exe&amp;quot;</strong> <strong>/testsettings:</strong>{path-to-test-settings-file} <strong>/testcontainer:</strong>{path-to-test-assembly1} <strong>/testcontainer:</strong>{path-to-test-assembly2} <strong>/testcontainer:</strong>{path-to-test-assembly3}&#8221;<strong>/&gt;</strong></p></blockquote>
<p>&lt;/Target&gt;</p>
<p>This will run all the tests in the assemblies that you passed and will generate a TestResults folder with all the information to measure Code Coverage (if you enabled it in the test settings file).</p>
<p>I hope you find this information useful. Please provide any feedback you consider necessary.</p>
<p>Thanks!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configuring TeamCity 7 to build your VS2010 .NET project using Git repository</title>
		<link>http://blogs.southworks.net/giglesias/2012/04/27/configuring-teamcity-7-to-build-your-vs2010-net-project-using-git-repository/</link>
		<comments>http://blogs.southworks.net/giglesias/2012/04/27/configuring-teamcity-7-to-build-your-vs2010-net-project-using-git-repository/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 19:18:19 +0000</pubDate>
		<dc:creator>giglesias</dc:creator>
				<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[TeamCity7]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/giglesias/?p=38</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/giglesias/2012/04/27/configuring-teamcity-7-to-build-your-vs2010-net-project-using-git-repository/" class="more-link">read more<img src="http://blogs.southworks.net/giglesias/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Hi everyone,</p>
<p>Recently I’ve been working with <a href="http://www.jetbrains.com/teamcity/">TeamCity 7</a> and getting involved in the continuous integration practice, so I would like to show my experience in this post.</p>
<p>For my project, “build” means the following things: compiling, checking Source Analysis, checking Code Analysis, running Unit Tests and measuring <a href="http://en.wikipedia.org/wiki/Code_coverage">Code Coverage</a>. Taking this into account, I will show you how to configure TeamCity 7 to perform all these tasks automatically in a VS2010 .NET solution, with .NET Framework 4 and a <a href="http://en.wikipedia.org/wiki/Git_(software)">Git</a> repository.</p>
<p>First of all I had to create a new project. I did this in the Administration &gt; Projects section, clicking <strong>Create new project</strong> and providing a name for it. After that, I had to create a new configuration for my project. This configuration has various “steps” to configure.</p>
<h1>Configuring General Settings</h1>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb.png" border="0" alt="image" width="1020" height="541" /></a></p>
<p>In this section I only provided a name for the new configuration. I left all the other values by default.</p>
<h1>Configuring Version Control Settings</h1>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image1.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb1.png" border="0" alt="image" width="985" height="101" /></a></p>
<p>In this section I had to specify the URL of the Git repository that I’ve been using to commit the source files of my application. To do this, I clicked <strong>Create</strong> <strong>and attach new VCS root</strong> and then, when the <strong>New VCS Root</strong> windows is displayed, I specified the URL of my repository and set the authentication method to Private Key, indicating the Private Key Path too.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image2.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb2.png" border="0" alt="image" width="968" height="767" /></a></p>
<p>TeamCity will be monitoring my repository according to the triggers that I specify in the build execution. On each build, TeamCity will search for changes in my repository and will execute the defined Build Steps. I will show all of this configuration in in the next sections.</p>
<h1>Configuring Build Steps</h1>
<p>This is one of the most important parts of the configuration process, because Build Steps are the actions that will be executed when a new build runs. In my configuration, I had to create 3 Build Steps as shown in the following picture:</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image3.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb3.png" border="0" alt="image" width="862" height="240" /></a></p>
<h2>Step 1 – Source Analysis, Compilation and Code Analysis</h2>
<p>This step will use a MSBuild runner with a ciserver.proj build file that resides inside the repository of the project. This build file has all the routines to check Source Analysis, Code Analysis and perform the compilation.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image4.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb4.png" border="0" alt="image" width="852" height="513" /></a></p>
<h4>Ciserver.proj file</h4>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image5.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb5.png" border="0" alt="image" width="926" height="788" /></a></p>
<p><strong>IMPORTANT:</strong> In order to successfully run this build file, you need to have <a href="http://stylecop.codeplex.com/releases/view/79972">Stylecop</a> and <a href="http://msbuildextensionpack.codeplex.com/">MSBuild Extension Pack</a> installed in the Server machine.</p>
<p>I defined all the paths to the working directory, FxCop and the Extension Pack at the beginning (they should be environment variables provided by TeamCity), so they can be passed to the tasks that are executed after that. In the ItemGroup tag I specified all the source code files in the repository, the assemblies to take into account, the rules to include, the soulution files and the ones that I want StyleCop to include in the checking.</p>
<ul>
<li><strong>RunSourceAnalysis task</strong>: It depends on the StyleCop.dll assembly of the MSBuild extension pack. This task will take the files defined in the ItemGroup section and the Settings.Stylecop specified and will perform the check generating a log file with all the information of the execution.</li>
<li><strong>Compile task</strong>: It will perform the compilation of the solution. Notice that it depends on the RunCodeAnalysis task.</li>
<li><strong>RunCodeAnalysis task</strong>: It will check Code Analysis in the assemblies defined in the ItemGroup section, and generate the results in a txt file. It also depends on the Compile task.</li>
</ul>
<p>All the result files generated by StyleCop and FxCop will then be used to show the Code Metrics reports in the TeamCity UI. I will show how to do this at the end of the post.</p>
<h2>Step 2 – Run tests</h2>
<p>This step will use MSTest runner with the Local.testsettings and test-metadata (.vsmdi) files generated by Visual Studio. In the test-metadata file I included the list of tests that I want the Build Process to execute.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image6.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb6.png" border="0" alt="image" width="795" height="660" /></a></p>
<p>All the other fields are left by default.</p>
<h2>Step 3 – Measure Code Coverage</h2>
<p>For this step, I decided to execute a Build file called teamCityCodeCoverage.proj with a MSBuild runner and measure the coverage manually instead of using one of the tools that TeamCity provides (NCover, PartCover, dotCover, etc).</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image7.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb7.png" border="0" alt="image" width="792" height="474" /></a></p>
<p>The only things that I had to provide in TeamCity were the path to the Build file, the .NET Framework used and the platform (x86 in this case). I left all the other fields by default.</p>
<h3>teamCityCodeCoverage.proj</h3>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image8.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb8.png" border="0" alt="image" width="1089" height="700" /></a></p>
<p>When the Tests were run in the previous Build Step, a sort of TestResults folder is created in a temp folder inside TeamCity path. It is the ArtifactDirectory path that is displayed in the previous image. Inside of it we have 2 important assets: The <strong>Out</strong> folder with all the assemblies of the test results, and the <strong>data.coverage</strong> file with the coverage information inside a <strong>In</strong> folder. All these stuff will be passed to the CoverageConvert.exe tool (this is an internal tool developed by the engineering excellence team), which will process them and produce a CodeCoverage.xml file with all the results of the measurement. But this is a lot of information to show in a report, so I used some assemblies to transform this xml into a html file with the summary of the Coverage.</p>
<h4>Folder with build files and Coverage tools</h4>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image9.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb9.png" border="0" alt="image" width="244" height="189" /></a></p>
<p><strong>NOTE:</strong> The disadvantage of measuring Code Coverage like this is that these assemblies have no maintenance and are a blackbox, although they were developed here in Southworks.</p>
<h1>Configuring Build Failure Conditions</h1>
<p>In this section you can specify when the Build should fail. Notice that you can add custom Build Conditions apart from the ones provided by TeamCity. In my case, I added two build failure conditions when there are Source Analysis or Code Analysis violations. Basically in the ciserver.proj file I show a status message when the check of Code Analysis and Source Analysis finishes. This will be printed in the Build log of TeamCity, so I added my custom failure conditions to fail the build if the status messages of Source Analysis and Code Analysis in the Build log of TeamCity are failure.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image10.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb10.png" border="0" alt="image" width="943" height="372" /></a></p>
<h1>Configuring Build Triggers</h1>
<p>In this section you can specify the triggering of the Build Process. In this case, I decided that the build process should start after a new commit is detected in the Git repository, so I chose a VCS trigger.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image11.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb11.png" border="0" alt="image" width="1098" height="232" /></a></p>
<h1>How to Show the Code Metrics Reports in the TeamCity UI</h1>
<p>TeamCity 7 provides <a href="http://confluence.jetbrains.com/display/TCD7/Including+Third-Party+Reports+in+the+Build+Results?pageVersion=5">custom report tags</a>. These ones are useful to show reports generated by other tools, like in this case, Source Analysis, Code Analysis and Code Coverage. To make this happen, we have to store these 3 reports as <a href="http://confluence.jetbrains.net/display/TCD7/Build+Artifact">artifacts</a> from the build.</p>
<p>To do this, we specify the path to these files in the General Settings section of the Project Configuration Wizard.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image12.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb12.png" border="0" alt="image" width="984" height="465" /></a></p>
<p>After that, we will create a new report tag for each report, and retrieve the report from the artifacts generated by the last successful build. To do this, click <strong>Administration</strong> at the top right corner, click <strong>your project’s name</strong> and the click the <strong>Report tabs</strong> tab. There you can create all the tabs that you want, specifying the build which the artifacts will be taken from, and the file names. These artifacts will be taken from the data-directory path of TeamCity, in this case, under Users\User\.BuildServer7\system\artifacts\{projectname}\….\{file-name}.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image13.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb13.png" border="0" alt="image" width="1135" height="216" /></a></p>
<p>Then, you can see the new tabs in the Project’s Home page, displaying the required reports.</p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image14.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb14.png" border="0" alt="image" width="674" height="189" /></a><a href="http://blogs.southworks.net/giglesias/files/2012/04/image15.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb15.png" border="0" alt="image" width="834" height="194" /></a></p>
<p><a href="http://blogs.southworks.net/giglesias/files/2012/04/image16.png"><img style="padding-left: 0px;padding-right: 0px;padding-top: 0px;border: 0px" src="http://blogs.southworks.net/giglesias/files/2012/04/image_thumb16.png" border="0" alt="image" width="1025" height="366" /></a></p>
<p>I know that the Code Analysis report is not very consumable, but I will show another alternatives for reporting it in another post.</p>
<p>I hope that you find all this information useful!</p>
<p>Thanks!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://blogs.southworks.net/giglesias/2011/02/21/hello-world/</link>
		<comments>http://blogs.southworks.net/giglesias/2011/02/21/hello-world/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 19:48:05 +0000</pubDate>
		<dc:creator>giglesias</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blogs.southworks.net/giglesias/?p=1</guid>
		<description><![CDATA[... <a href="http://blogs.southworks.net/giglesias/2011/02/21/hello-world/" class="more-link">read more<img src="http://blogs.southworks.net/giglesias/wp-content/themes/southworks/assets/img/arrow-blue.png" width="12" height="12" alt="" /></a>]]></description>
			<content:encoded><![CDATA[<p>Hi, this is my first Southworks post! I will be sharing my knowledge and experiences in this blog from now on. Until then try reading one of our other Southworks Blogs (http://blogs.southworks.net). See you soon!</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
