<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>John Socha-Leialoha's Blog</title><link>http://blogs.msdn.com/b/jsocha/</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 5.6.583.21163 (Build: 5.6.583.21163)</generator><item><title>How to Name Test Methods</title><link>http://blogs.msdn.com/b/jsocha/archive/2012/03/11/how-to-name-test-methods.aspx</link><pubDate>Sun, 11 Mar 2012 17:30:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10281061</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10281061</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2012/03/11/how-to-name-test-methods.aspx#comments</comments><description>&lt;p&gt;I really like BDD (Behavior Driven Development) and it’s structure for helping to focus on behavior instead of implementation when you write unit tests. Some time ago I ran across a blog post by my former colleague in the patterns &amp;amp; practices group Daniel Cazzulino: &lt;a href="http://blogs.clariusconsulting.net/kzu/writing-meaningful-self-documenting-behavior-oriented-tests/"&gt;Writing meaningful, self-documenting, behavior-oriented tests&lt;/a&gt;. Another good post, which has more links to BDD is this one: &lt;a href="http://blogs.clariusconsulting.net/kzu/approaching-behavior-driven-development-bdd-from-a-test-driven-development-tdd-perspective/"&gt;Approaching Behavior Driven Development (BDD) from a Test Driven Development (TDD) perspective&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;As a result, I started naming my tests with names like this, using underscores to separate the different BDD keywords:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestMethod]&lt;br /&gt;[Description(&lt;span style="color: #006080"&gt;&amp;quot;Column order is different, but tables match&amp;quot;&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShouldNotThrow_WhenAreEqual_GivenSameData_ButColumnOrderDifferent()&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;This worked reasonably well in Visual Studio 2010 tests results window because I could show the Description column. That way the test results included an easy to read description (the Description attribute), as well as the Given/When/Then behind the test (although I put the Then part first and called it Should):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0243.image_5F00_237559EE.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/6318.image_5F00_thumb_5F00_2A286371.png" width="740" height="48" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then along came Dev11 beta. They’ve completely changed the test results experience. The new version, at least in the beta, doesn’t support the description attribute, so you only see the test method names, resulting in my test results looking like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/1738.image_5F00_46900580.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/8267.image_5F00_thumb_5F00_0A6439D8.png" width="229" height="130" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Argh! That makes it really hard to read test methods. Plus, I wasn’t completely happy with the long test methods anyway. What to do?&lt;/p&gt;

&lt;h2&gt;Rethinking Test Method Naming&lt;/h2&gt;

&lt;p&gt;I had a nice conversation with another former p&amp;amp;p colleague, Peter Provost, who is a PM working on the test experience. He suggested that I put the BDD description into the Description attribute. I decided to try this out, and so far I’m liking the change:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;// Column order is different, but tables match&lt;/span&gt;&lt;br /&gt;[TestMethod]&lt;br /&gt;[Description(&lt;span style="color: #006080"&gt;&amp;quot;Given two tables And same data But different column order | When TableAssert | Then true&amp;quot;&lt;/span&gt;)]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ColumnOrderDoesntMatter()&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;Here is what this looks like in the new test runner:&lt;/div&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/7288.image_5F00_4B62BD9E.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/6683.image_5F00_thumb_5F00_7D5A5E28.png" width="233" height="30" /&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;One nice thing about this approach is that the BDD description is easier to read and it can be richer without overwhelming the method name.&lt;/p&gt;

&lt;h2&gt;Wishful Thinking&lt;/h2&gt;

&lt;p&gt;I think it would be really cool (just my opinion) if this had a rich tooltip that showed the class information (the current tooltop does) and also the Description attribute. It would also be really cool if I could write an VS extension that would format my descriptions into multiple lines with keywords like Given, When, and Then in bold. Hint, hint VS guys…&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10281061" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/TDD/">TDD</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Unit+Tests/">Unit Tests</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/-NET/">.NET</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Visual+Studio+11/">Visual Studio 11</category></item><item><title>Retrieving TFS Results from a Tree Query</title><link>http://blogs.msdn.com/b/jsocha/archive/2012/02/22/retrieving-tfs-results-from-a-tree-query.aspx</link><pubDate>Wed, 22 Feb 2012 18:22:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10271165</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10271165</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2012/02/22/retrieving-tfs-results-from-a-tree-query.aspx#comments</comments><description>&lt;p&gt;I recently needed to retrieve the results from a TFS tree query using .NET code, via calls to the TFS API. It was easy to find examples for retrieving a set of work items from a flat query, but I couldn’t find any information about how to retrieve a tree. I did find a few people talking about some ways to do it, but they said it was too slow.&lt;/p&gt;  &lt;p&gt;In this blog post I’ll show you a very fast way to retrieve a tree of results. Let’s start with the query I’m using:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;SELECT&lt;/span&gt; [System.Id], &lt;br /&gt;       [System.Title], &lt;br /&gt;       [Microsoft.VSTS.Common.BacklogPriority], &lt;br /&gt;       [System.AssignedTo], &lt;br /&gt;       [System.State, &lt;br /&gt;       [Microsoft.VSTS.Scheduling.RemainingWork], &lt;br /&gt;       [Microsoft.VSTS.CMMI.Blocked], &lt;br /&gt;       [System.WorkItemType] &lt;br /&gt;&lt;span style="color: #0000ff"&gt;  FROM&lt;/span&gt; &lt;font style="background-color: #ffff00"&gt;WorkItemLinks&lt;/font&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt; WHERE&lt;/span&gt; (&lt;br /&gt;        Source.[System.TeamProject] = @project &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;AND&lt;/span&gt; Source.[System.WorkItemType] &lt;span style="color: #0000ff"&gt;IN&lt;/span&gt; (&lt;span style="color: #006080"&gt;'Product Backlog Item'&lt;/span&gt;, &lt;span style="color: #006080"&gt;'Bug'&lt;/span&gt;)&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;AND&lt;/span&gt; (&lt;br /&gt;        Source.[System.State] &amp;lt;&amp;gt; &lt;span style="color: #006080"&gt;'Removed'&lt;/span&gt; &lt;br /&gt;        &lt;span style="color: #0000ff"&gt;AND&lt;/span&gt; Source.[System.State] &amp;lt;&amp;gt; @closedState&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; )&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; )&lt;br /&gt;&lt;font style="background-color: #f4f4f4"&gt;    &lt;/font&gt;&lt;span style="color: #0000ff"&gt;AND&lt;/span&gt; [System.Links.LinkType] = &lt;span style="color: #006080"&gt;'System.LinkTypes.Hierarchy-Forward'&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;AND&lt;/span&gt; Target.[System.WorkItemType] &amp;lt;&amp;gt; &lt;span style="color: #006080"&gt;''&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;ORDER&lt;/span&gt; &lt;span style="color: #0000ff"&gt;BY&lt;/span&gt; [Microsoft.VSTS.Common.StackRank], [Microsoft.VSTS.Common.Priority], [System.Id] mode(&lt;span style="color: #0000ff"&gt;Recursive&lt;/span&gt;)&lt;/p&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;I’ve highlighted the FROM location, which in this case is WorkItemLinks, which you need to use in order to retrieve a hierarchy. Flat querys pull from WorkItems.&lt;/p&gt;

&lt;p&gt;Retrieving a tree of work items actually takes two queries. The first query returns a list of work item IDs that contains SourceId and TargetId values (parent and child IDs when the link type is Hierarchy-Forward as here). However, the query does not return any of the details of the work item. For that you’ll need a second query (described later).&lt;/p&gt;

&lt;p&gt;The tree query above also contains two parameters (@project and @closedState) that will need values. Here is a code snippet that shows supplying values and retrieving the list of IDs:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt; parameters = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt;();&lt;br /&gt;parameters.Add(&lt;span style="color: #006080"&gt;&amp;quot;project&amp;quot;&lt;/span&gt;, _tfsProjectName);&lt;br /&gt;parameters.Add(&lt;span style="color: #006080"&gt;&amp;quot;closedState&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;Done&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;var treeQuery = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Query(_workItemStore, wiql, parameters);&lt;br /&gt;WorkItemLinkInfo[] links = treeQuery.RunLinkQuery();&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;The first part of the code creates a dictionary with the parameter values to use when running the query. You must use the RunLinkQuery method to run the query, instead of the RunQuery method, when working with WorkItemLinks. Calling RunQuery when you reference WorkItemLinks will throw an exception.&lt;/p&gt;

&lt;p&gt;The links array returned from this query might look something like this:&lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="2" width="100"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="25"&gt;&lt;strong&gt;SourceId&lt;/strong&gt;&lt;/td&gt;

      &lt;td valign="top" width="25"&gt;&lt;strong&gt;TargetId&lt;/strong&gt;&lt;/td&gt;

      &lt;td valign="top" width="25"&gt;&lt;strong&gt;LinkTypeId&lt;/strong&gt;&lt;/td&gt;

      &lt;td valign="top" width="25"&gt;&lt;strong&gt;IsLocked&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;0&lt;/td&gt;

      &lt;td&gt;23268&lt;/td&gt;

      &lt;td&gt;0&lt;/td&gt;

      &lt;td&gt;FALSE&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;23268&lt;/td&gt;

      &lt;td&gt;23339&lt;/td&gt;

      &lt;td&gt;2&lt;/td&gt;

      &lt;td&gt;FALSE&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;23268&lt;/td&gt;

      &lt;td&gt;23464&lt;/td&gt;

      &lt;td&gt;2&lt;/td&gt;

      &lt;td&gt;FALSE&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;0&lt;/td&gt;

      &lt;td&gt;23633&lt;/td&gt;

      &lt;td&gt;0&lt;/td&gt;

      &lt;td&gt;FALSE&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;23633&lt;/td&gt;

      &lt;td&gt;24664&lt;/td&gt;

      &lt;td&gt;2&lt;/td&gt;

      &lt;td&gt;FALSE&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;These results represent a tree. In our case the tree has just one level of children. As an example, work item 23268 is the parent of two other work items: 23339 and 23464. However, more importantly, the results of running this query do not return any of the fields from the query. How do you get those fields? You have to run another query that returns the results. The second query needs to use the set of columns from the original query, but pull from the WorkItems “table” instead of WorkItemLinks.&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;// Build the list of work items for which we want to retrieve more information&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;[] ids = (from WorkItemLinkInfo info &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; links&lt;br /&gt;             select info.TargetId).ToArray();&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;// Next we want to create a new query that will retrieve all the column values from the original query, for&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;// each of the work item IDs returned by the original query.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;br /&gt;var detailsWiql = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringBuilder();&lt;br /&gt;detailsWiql.AppendLine(&lt;span style="color: #006080"&gt;&amp;quot;SELECT&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; first = &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (FieldDefinition field &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; treeQuery.DisplayFieldList)&lt;br /&gt;{&lt;br /&gt;    detailsWiql.Append(&lt;span style="color: #006080"&gt;&amp;quot;    &amp;quot;&lt;/span&gt;);&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!first)&lt;br /&gt;        detailsWiql.Append(&lt;span style="color: #006080"&gt;&amp;quot;,&amp;quot;&lt;/span&gt;);&lt;br /&gt;    detailsWiql.AppendLine(&lt;span style="color: #006080"&gt;&amp;quot;[&amp;quot;&lt;/span&gt; + field.ReferenceName + &lt;span style="color: #006080"&gt;&amp;quot;]&amp;quot;&lt;/span&gt;);&lt;br /&gt;    first = &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;detailsWiql.AppendLine(&lt;span style="color: #006080"&gt;&amp;quot;FROM WorkItems&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;// Get the work item details&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;br /&gt;var flatQuery = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Query(_workItemStore, detailsWiql.ToString(), ids);&lt;br /&gt;WorkItemCollection details = flatQuery.RunQuery();&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Here is what this code does:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Create an array of work item ids in the same order as returned by the tree query&lt;/li&gt;

  &lt;li&gt;Build a new query that has this form: “SELECT {field list} FROM WorkItems”. The Query instance used to retrieve the tree of work item IDs has a property called DisplayFieldList that contains the the list of fields contained in the query. The code uses this list to build a new flat query that returns all the fields from the original tree query.&lt;/li&gt;

  &lt;li&gt;Call the RunQuery method on the new flat query&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The set of work items returned by this new query will be in exactly the same order as the link query results at the top of this post. You can then “combine” these two results sets to build a tree and use this tree as you need.&lt;/p&gt;

&lt;p&gt;Using this approach is very fast because there are just two queries. I don’t have any inside knowledge about how the TFS client using the SDK to retrieve results, but I wouldn’t be surprised if it’s very much like what I’ve outlined here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10271165" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/-NET/">.NET</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/TFS/">TFS</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2300_/">C#</category></item><item><title>Allowing Localizing after-the-fact using MUI</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/12/14/allowing-localizing-after-the-fact-using-mui.aspx</link><pubDate>Wed, 14 Dec 2011 22:46:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10247847</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10247847</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/12/14/allowing-localizing-after-the-fact-using-mui.aspx#comments</comments><description>&lt;p&gt;Here is the problem. We built an English-only C++ application. However, now some of our customers are asking how they can translate the application into other languages. We don’t have the budget to provide translated versions ourselves, and they’d be happy to do the work themselves. Is there a way they can translate our application after the fact? And without our involvement?&lt;/p&gt;  &lt;p&gt;I thought the answer was “no,” until someone suggested MUI. My first reaction was “what’s that?” MUI, as it turns out, stands for &lt;a href="http://msdn.microsoft.com/en-us/library/dd319073(v=VS.85).aspx"&gt;Multilingual User Interface&lt;/a&gt; and has been supported in one way or another since Windows XP. I did not know this. The idea is that you remove the resources from your main binaries and instead put them into MUI files, which are just DLLs with a different extension. For example:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;MyApplication.exe&amp;#160; &amp;lt;— No resources      &lt;br /&gt;en-US       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; MyApplication.exe.mui&amp;#160; &amp;lt;— Language-neutral (in this case English)      &lt;br /&gt;de       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; MyApplication.exe.mui&amp;#160; &amp;lt;— German      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In the picture above, the first MUI file (under the en-US directory) contains the English resources (strings, dialog boxes, etc.). This MUI file is marked as both the en-US file and the language-neutral file that will be used when Windows can’t find a better match.&lt;/p&gt;  &lt;p&gt;The second MUI (under the de directory) contains the German resources that will be used whenever the Windows’ current language is German (weather that be in Germany, or any other country).&lt;/p&gt;  &lt;p&gt;With very little work (less than a day), we were able to build a version of our application that our customers can translate to their heart’s content. Below I describe the steps for a developer to make their application translatable after the fact.&lt;/p&gt;  &lt;h1&gt;Before you Start&lt;/h1&gt;  &lt;p&gt;In order to create an MUI-aware application, you’ll need to install the Windows 7 SDK, which is where you’ll find &lt;a href="http://msdn.microsoft.com/en-us/library/dd319113(v=VS.85).aspx"&gt;MUIRCT&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;Creating the MUI Files&lt;/h2&gt;  &lt;p&gt;You may not need to make many changes in your application to make all of this work if you only support Vista or later. If you require Windows XP support, you’ll need to read the section below.&lt;/p&gt;  &lt;p&gt;The first step is to run a program called &lt;a href="http://msdn.microsoft.com/en-us/library/dd319113(v=VS.85).aspx"&gt;MUIRCT&lt;/a&gt; that will move the resources from your main executables into satellite executables. This program requires a config file that describes which resources to move over. Here is the file I used:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #800000"&gt;xml&lt;/span&gt; &lt;span style="color: #ff0000"&gt;version&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;encoding&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt;?&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;localization&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;win32Resources&lt;/span&gt; &lt;span style="color: #ff0000"&gt;fileType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;Application&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;neutralResources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resourceType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;typeNameId&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#16&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;neutralResources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;localizedResources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resourceType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;typeNameId&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#2&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resourceType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;typeNameId&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#3&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resourceType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;typeNameId&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#4&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resourceType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;typeNameId&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#5&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resourceType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;typeNameId&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#6&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resourceType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;typeNameId&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#9&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resourceType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;typeNameId&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#11&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;         &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;resourceType&lt;/span&gt; &lt;span style="color: #ff0000"&gt;typeNameId&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;#16&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;localizedResources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;win32Resources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;resources&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;localization&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;For more details, read &lt;a href="http://msdn.microsoft.com/en-us/library/dd319100(v=VS.85).aspx"&gt;Preparing a Resource Configuration File&lt;/a&gt; on MSDN.&lt;/p&gt;

&lt;p&gt;Next you’ll need to run &lt;a href="http://msdn.microsoft.com/en-us/library/dd319113(v=VS.85).aspx"&gt;MUIRCT&lt;/a&gt; to split your files:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;muirct.exe -q muiconfig.xml -v 1 -x 0x0409  ..\MyApplication.exe MyApplication.exe en-US\MyApplication.exe.mui&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;The “..\MyApplication” refers to the original EXE that contains all the language-neutral resources (the 0x409 says they’re en-US resources). The second-to-last parameter, “MyApplication.exe” is the name that will be used for the new version that contains none of the resources being moved. Finally, the last parameter contains the name of the MUI file that will be created to contain all the resources that are called out in the config file as resource you want to move.&lt;/p&gt;

&lt;p&gt;If you have no need to support Windows XP, you’re done.&lt;/p&gt;

&lt;h2&gt;Supporting Windows XP&lt;/h2&gt;

&lt;p&gt;Windows Vista and later automatically handle locating and using the correct MUI file for resources. However, if your application needs to be able to run on Windows XP as well, you’ll need to make some changes to your code. In our case that was really easy because the calls to load strings were all encapsulated in a helper class. The idea is that you’ll need to call a new API that will located and load the best-match MUI file:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;std::vector&amp;lt;WCHAR&amp;gt; moduleName(MAX_PATH);&lt;br /&gt;&lt;br /&gt;GetModuleFileName(hModule, &amp;amp;moduleName[0], moduleName.size());&lt;br /&gt;hInstance = ::LoadMUILibrary(moduleName.data(), MUI_LANGUAGE_NAME, 0);&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p align="left"&gt;The first two lines get the name of the executable that we’re running. The last line is where the magic happens. &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd318709(v=vs.85).aspx"&gt;LoadMUILibrary&lt;/a&gt; is a function that in Windows XP will locate the appropriate satellite MUI file, load that file, and return an instance handle to that file. In Windows Vista and later, this call returns the instance handle for your main executable because the system automatically handles resource location in calls like LoadString.&lt;/p&gt;

&lt;p align="left"&gt;Additionally, you’ll need to ensure you link to muiload.lib. I like to use a pragma in my source files, rather than setup additional libraries in the link options, using a line like this:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #cc6633"&gt;#pragma&lt;/span&gt; comment(lib, &lt;span style="color: #006080"&gt;&amp;quot;muiload.lib&amp;quot;&lt;/span&gt;)&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h2&gt;&lt;/h2&gt;

&lt;h2&gt;Localizing MUI Files&lt;/h2&gt;

&lt;p&gt;I’m not an expert on localization, so I’m not sure what most companies use to localize native Windows applications. Here at Microsoft we use a tool called LocStudio, and I understand there are similar programs available outside of Microsoft.&lt;/p&gt;

&lt;p&gt;Whichever tool you use, here’s what you have to do:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Create a new directory for the new locale using the two-letter language identifier (like “de” for German)&lt;/li&gt;

  &lt;li&gt;Copy the language-neutral MUI file&lt;/li&gt;

  &lt;li&gt;Translate the strings (and possibly change control sizes and positions in dialogs)&lt;/li&gt;

  &lt;li&gt;Copy the localized MUI file into the new directory (“de” in this example)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just a quick note about Visual Studio. You can open native Windows executable files and edit the resources in them with Visual Studio. However, you cannot save changes you make to MUI files, so you’ll have to use another tool. Again, I don’t have knowledge of those other tools.&lt;/p&gt;

&lt;h2&gt;Working with Signed Binaries&lt;/h2&gt;

&lt;p&gt;What happens if the original binaries and MUI files are code signed? It just works. I didn’t know the answer to this so I tested it. I used &lt;a href="http://msdn.microsoft.com/en-us/library/dd319113(v=VS.85).aspx"&gt;MUIRCT&lt;/a&gt; to split the files, and then code-signed both the main executable and the MUI file. Then I made a localized copy of the MUI file for German that was not signed. I was able to run this and see the English strings when I ran with English as the default language for Windows. When I switched to German and ran the program again, it showed the German strings from the un-signed German MUI files.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10247847" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Localization/">Localization</category></item><item><title>Capturing Code Coverage for Coded UI Tests</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/12/02/capturing-code-coverage-for-coded-ui-tests.aspx</link><pubDate>Fri, 02 Dec 2011 18:45:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10243793</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10243793</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/12/02/capturing-code-coverage-for-coded-ui-tests.aspx#comments</comments><description>&lt;p&gt;You would think that simply running coded UI tests with everything setup for capturing code coverage would just work, right? And if you’re running your coded UI tests on a 32-bit operating system, it will.&lt;/p&gt;  &lt;p&gt;However, if you’re running your tests on a 64-bit operating system, chances are you’ll see the test results (pass/fail), but you won’t see any code coverage results. Why not? And how do you fix it?&lt;/p&gt;  &lt;p&gt;By default, the test runner in Visual Studio (and on the TFS build server) run as a 32-bit process, which also means that the code coverage tools are the 32-bit versions. When you run unit tests, the test runner loads all the assemblies into the test runner’s process, which means that .NET assemblies will be run as 32-bit assemblies.&lt;/p&gt;  &lt;p&gt;The problem occurs when you used coded UI tests. In this case, the executable assembly is &lt;strong&gt;not&lt;/strong&gt; loaded into the test runners process. Instead, it’s launched in a new process. If you assembly is marked as Any CPU, and you running on a 64-bit OS, the application you’re testing will now be a 64-bit application, which means the 32-bit code coverage code won’t be able to capture any code coverage for your code UI tests.&lt;/p&gt;  &lt;p&gt;How do you fix this? Basically you want to make sure the builds used for test runs have the EXE targeted for 32-bit rather than Any CPU. One way is to modify the solution so it builds targets the main EXE to 32-bit, as shown here (this is the Configuration Manager dialog for the solution):&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/8267.image_5F00_49CFE931.png" width="392" height="208" /&gt;&lt;/p&gt;  &lt;p&gt;The other option is to change the target platform in the build definition&lt;/p&gt;  &lt;p&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/2620.image_5F00_7B5B56C6.png" width="402" height="77" /&gt;&lt;/p&gt;    &lt;p&gt;Using either approach will force the assembly that you want to test to be built for the 32-bit platform.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10243793" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/-NET/">.NET</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/TFS/">TFS</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Acceptance+Tests/">Acceptance Tests</category></item><item><title>Shrinking the Arrow on the WPF Expander</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/10/05/shrinking-the-arrow-on-the-wpf-expander.aspx</link><pubDate>Thu, 06 Oct 2011 01:57:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10220967</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10220967</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/10/05/shrinking-the-arrow-on-the-wpf-expander.aspx#comments</comments><description>&lt;p&gt;My goal was simple. I needed a smaller arrow in the WPF Expander control to help conserve screen real-estate. Here is the before and after:&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="100"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="50"&gt;Before:&lt;/td&gt;        &lt;td valign="top" width="50"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/6813.image_5F00_7F0F13FE.png" width="23" height="22" /&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="50"&gt;After:&lt;/td&gt;        &lt;td valign="top" width="50"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/4353.image_5F00_4A0284CE.png" width="18" height="17" /&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The arrow on the right is 80% of the original size.&lt;/p&gt;  &lt;p&gt;So how did I accomplish this? It turned out to be far simpler than any of the blog posts I found on the subject. They all suggested using Expression Blend to copy the full template and them modify it. But you can use a RenderTransform to reduce the size:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Expander&lt;/span&gt; &lt;span style="color: #ff0000"&gt;Header&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;{Binding Name}&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;FontSize&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;16&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Expander.RenderTransform&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;ScaleTransform&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ScaleX&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;.8&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;ScaleY&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;.8&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Expander.RenderTransform&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Expander&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Notice that I bumped the font size up to 16. When multiplied by .8, this gives a final font size of 12.8, which is a nice size.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10220967" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/-NET/">.NET</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2300_/">C#</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/WPF/">WPF</category></item><item><title>Delay Signing a C++/CLI Assembly</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/09/09/delay-signing-a-c-cli-assembly.aspx</link><pubDate>Sat, 10 Sep 2011 00:40:51 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10208814</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10208814</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/09/09/delay-signing-a-c-cli-assembly.aspx#comments</comments><description>&lt;p&gt;This should be easy, right? Just set the link options to delay sign the assembly with an SNK file. There were two issues I ran into, which I’ll describe here.&lt;/p&gt;  &lt;h2&gt;Fixing Delay Signing in SP1&lt;/h2&gt;  &lt;p&gt;I used the /DELAYSIGN and /KEYFILE settings in the properties page for my C++/CLI project and everything compiled just fine. However, when I tried to use an object from this DLL, I got this message::&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;CS1577: Assembly generation failed … &lt;strong&gt;does not have a strong name&lt;/strong&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This certainly wasn’t what I expected. My first step was to double-check the signing on the assembly. I used the following command-line command to check:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;sn -T &lt;em&gt;AssemblyName&lt;/em&gt;.dll&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;When I ran this command, it reported “AssemblyName.dll &lt;strong&gt;does not represent a strongly named assembly&lt;/strong&gt;&amp;quot;. Obviously the properties I set in the project settings dialog weren’t working. After quite a bit of searching, I found a blog post by &lt;a href="http://blogs.msdn.com/b/vcblog/archive/2011/03/11/10140139.aspx"&gt;Amit Mohindra&lt;/a&gt; that explained the problem, which is a change in Visual Studio 2010 SP1.&lt;/p&gt;

&lt;p&gt;The blog post had suggestions on how to fix the problem, but it seemed like quite a bit of work. I tried another approach, which worked just fine.&lt;/p&gt;

&lt;h2&gt;Signing via AssemblyInfo.cpp&lt;/h2&gt;

&lt;p&gt;I added an new file called AssemblyInfo.cpp to my project, which has the following contents:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;p&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;stdafx.h&amp;quot;&lt;br /&gt; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; System;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;using&lt;/span&gt; &lt;span style="color: #0000ff"&gt;namespace&lt;/span&gt; System::Reflection;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;[assembly:AssemblyKeyFile(&lt;span style="color: #006080"&gt;&amp;quot;myKey.snk&amp;quot;&lt;/span&gt;)];&lt;br /&gt;[assembly:AssemblyDelaySign(true)];&lt;/p&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;This took care of signing the assembly, which I verified using the sn command.&lt;/p&gt;

&lt;h2&gt;Dealing with C++/CLI vs C# Assemblies&lt;/h2&gt;

&lt;p&gt;One this was all working, we added a call from our C# EXE into the C++/CLI assembly, and got this run-time error:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Could not load file or assembly 'AssemblyName, Version=0.0.0.0, Culture=neutral, PublicKeyToken=…' or one of its dependencies. An attempt was made to load a program with an &lt;strong&gt;incorrect format&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Incorrect format? Huh?&lt;/p&gt;

&lt;p&gt;With a little more searching, I found the problem, and now that I understand the problem, it makes perfect sense. First, the solution. You need to change the &lt;strong&gt;Platform&lt;/strong&gt; from &lt;strong&gt;Any CPU&lt;/strong&gt; to &lt;strong&gt;x86&lt;/strong&gt; for you main EXE (or x64 if you’re building a 64-bit version) to match the bitness of your C++/CLI assembly:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/8524.image_5F00_18E08B20.png" width="481" height="68" /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here’s why we had to make this change. Our C++/CLI assembly is calling not a pure .NET assembly since it’s making calls to windows APIs. As such, the C++/CLI assembly needs to be either 32- or 64-bit. It can’t be both because of the native C++ code it contains. A .NET assembly that is built for Any CPU can run as either a 32- or 64-bit process, but you can’t load a 32-bit DLL into a 64-bit process, hence the error. Building a 32-bit .NET EXE that loads the 32-bit C++/CLI DLL fixes the problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10208814" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/-NET/">.NET</category></item><item><title>Interpreting C++ Code Coverage Results</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/08/17/interpreting-c-code-coverage-results.aspx</link><pubDate>Wed, 17 Aug 2011 19:48:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10196925</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10196925</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/08/17/interpreting-c-code-coverage-results.aspx#comments</comments><description>&lt;p&gt;You’ve finally gotten code coverage results for your C++ code. But now your code coverage numbers are lower than you expected. Why is that? And how do you get around it?&lt;/p&gt;  &lt;p&gt;There are several issues that make C++ code coverage data “noisy” and/or inaccurate. First, if you use the standard C++ libraries, you’ll find the code coverage results littered with entries from the std namespace, which represents classes and methods provided by Microsoft. Clearly, you don’t want library classes provided by Microsoft to impact your code coverage results. Especially if it lowers your numbers.&lt;/p&gt;  &lt;p&gt;Another issue has to do with using template classes. Look at this example, which is a real example from some of our code:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/4722.clip_5F00_image002_5F00_15F51109.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0525.clip_5F00_image002_5F00_thumb_5F00_3C56F454.jpg" width="485" height="147" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You would probably expect this to show 100% code coverage in Visual Studio (or TFS). It doesn’t. In fact, it reports 72% code coverage. The problem is the return statement at the end. Visual Studio reports code coverage in terms of &lt;a href="http://msdn.microsoft.com/en-us/library/cc667391.aspx"&gt;blocks covered/not covered&lt;/a&gt; (also &lt;a href="http://msdn.microsoft.com/en-us/library/dd299398.aspx"&gt;this article&lt;/a&gt;). There are blocks in the wstring class that aren’t being covered in this method.&lt;/p&gt;  &lt;p&gt;How do you fix this problem?&lt;/p&gt;  &lt;h1&gt;Building a Code Coverage Report&lt;/h1&gt;  &lt;p&gt;There are probably many ways to provide better code coverage numbers for C++ code. I chose to write a report for TFS that reads results from the data warehouse and process them to produce more “useful” results. Here is an overview of what the report does with the data (I’ll describe each in more detail):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Use lines instead of blocks for coverage information &lt;/li&gt;    &lt;li&gt;Treat partially covered lines as covered &lt;/li&gt;    &lt;li&gt;Collapse concrete template instances into a “common” instance &lt;/li&gt;    &lt;li&gt;Use the method results with the highest coverage &lt;/li&gt;    &lt;li&gt;Filter out namespaces and functions &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following sections describe each of these bullets in more detail.&lt;/p&gt;  &lt;h3&gt;Use lines instead of blocks, and treat partially covered as covered&lt;/h3&gt;  &lt;p&gt;I debated a long time before making these changes. Visual Studio reports code coverage results based on block coverage, so I wasn’t sure how people would react to using lines instead. However, switching to lines and also treating partially covered lines as covered mitigates the issue I described above. It does mean we’re over-reporting coverage for lines that have conditional code, but our style guidelines call for using multiple lines in such cases, so this is probably a small issue.&lt;/p&gt;  &lt;p&gt;Alternatively, there are Visual Studio APIs, found in the &lt;a href="http://msdn.microsoft.com/en-us/library/dd347161.aspx"&gt;Microsoft.VisualStudio.Coverage.Analysis&lt;/a&gt; namespace that could be used to process the code coverage results. I haven’t tried this, and it would have taken more time than writing a report.&lt;/p&gt;  &lt;h3&gt;Collapse template instances&lt;/h3&gt;  &lt;p&gt;We have some template classes that we use as base classes. The methods are well covered with unit tests. However not all concrete instances call the base methods, and we have a number of concrete instances of these classes. The result is that we get partial code coverage multiplied by the number of concrete instances. Our desire is to know how much coverage we achieve for the code we wrote, not for compiler-generated code. As such, I chose to collapse concrete instances. For example, we have a template called BaseControl, with a concrete instance called BaseControl&amp;lt;ItreeView&amp;gt;. In the report, I collapse this into BaseControl__ so that we can “combine” the results for each base method from sub classes. This brings us to the next topic.&lt;/p&gt;  &lt;h3&gt;Use the highest coverage results&lt;/h3&gt;  &lt;p&gt;We have several different runs on our build server, and we want to combine these in the report results. For example, we have unit tests run during gated check-ins, and we runs all our automated acceptance tests nightly. The acceptance tests cover some code (such as UI code) that isn’t covered by the unit tests, and visa versa.&lt;/p&gt;  &lt;p&gt;Because of the testing approach we’re using, the unit tests are written in C++/CLI and include the product code directly into the test DLL (see &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx"&gt;Writing Unit Tests in Visual Studio for Native C++&lt;/a&gt;) whereas our acceptance tests are written in C# and use the production DLL. This results in the DLL names being different between these two runs. The report I created replaces these different names with a common name so the data can be combine.&lt;/p&gt;  &lt;p&gt;One the report collapses template instances and combined results from DLLs with different names, but representing the same code, there may be more than one record (result) for each method in the product code. How do you combine these records? TFS stores the name of the class and method, as well as lines covered, not covered, and partially covered (and also block information). I chose to use the record for each method that has the highest coverage. So if you have different test runs that cover different parts of a method, choosing the result with the highest coverage will under-report code coverage since there’s no way to tell how much overlap there is between different result records.&lt;/p&gt;  &lt;h1&gt;Filter out namespaces and functions&lt;/h1&gt;  &lt;p&gt;In my MSDN article, &lt;a href="http://msdn.microsoft.com/en-us/magazine/hh205645.aspx"&gt;Agile C++ Development and Testing with Visual Studio and TFS&lt;/a&gt;, I talked about filtering out common patterns, such as “std::”, from the results because this represents library code that we don’t want to include. Since then, I’ve found even more patterns, so the new report I created excludes a much larger list.&lt;/p&gt;  &lt;h1&gt;Using the Results&lt;/h1&gt;  &lt;p&gt;The results of all this work were very significant. Switching from block to line coverage moved our code coverage results up from 62% for one DLL to about 70%. Doing all the other work took this number up to 87%, which is more of what I expected to see since we used TDD to write all the code in that DLL.&lt;/p&gt;  &lt;h1&gt;Using the Report&lt;/h1&gt;  &lt;p&gt;If you’ve never added a new report to your reporting site, you can find some instructions here: &lt;a title="http://blogs.msdn.com/b/aaronbjork/archive/2010/07/30/microsoft-visual-studio-scrum-1-0-updated-sprint-burndown-report.aspx" href="http://blogs.msdn.com/b/aaronbjork/archive/2010/07/30/microsoft-visual-studio-scrum-1-0-updated-sprint-burndown-report.aspx"&gt;http://blogs.msdn.com/b/aaronbjork/archive/2010/07/30/microsoft-visual-studio-scrum-1-0-updated-sprint-burndown-report.aspx&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;img alt="Source Code" align="middle" src="http://archive.msdn.microsoft.com/Images/SourceCode.gif" /&gt; &lt;a href="http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mpsddev&amp;amp;DownloadId=15624"&gt;Code Coverage.rdl&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once you install the report in your team project, you’ll see something that looks like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/2766.image_5F00_7C20DAD9.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0284.image_5F00_thumb_5F00_54E691A4.png" width="629" height="330" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Customizing the Report&lt;/h2&gt;  &lt;p&gt;There are several places where you can customize the report. Open the report in Report Manager (right click on the &lt;strong&gt;Reports&lt;/strong&gt; node in &lt;strong&gt;Team Explorer&lt;/strong&gt; inside Visual Studio and select &lt;strong&gt;Show Report Site&lt;/strong&gt;), click the &lt;strong&gt;Properties&lt;/strong&gt; tab, then click &lt;strong&gt;Parameters&lt;/strong&gt;. You’ll see something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/1373.image_5F00_429DCAE2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/1185.image_5F00_thumb_5F00_345F51F2.png" width="635" height="311" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;There are several hidden parameters you can use to provide more control over what you see in the report:&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="622"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="133"&gt;MinStartOffset&lt;/td&gt;        &lt;td valign="top" width="487"&gt;The default is -5, which means the report will only show builds within the last 5 days.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;IgnoreBuilds&lt;/td&gt;        &lt;td valign="top" width="487"&gt;A set of build definitions that you don’t want to show up in the Build Definitions parameter. I’ve used the name “empty” when there are no builds I want to ignore.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;IgnoreAssemblies&lt;/td&gt;        &lt;td valign="top" width="487"&gt;A list of assemblies that you want to exclude from the report. This is useful to us because we have several projects that share source, so they’re all part of the same gated build definition.&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;DefaultBuildDefinitions&lt;/td&gt;        &lt;td valign="top" width="487"&gt;The list of build definitions that you want to be selected when you first run a report.&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Remember to click &lt;strong&gt;Apply&lt;/strong&gt; to save changes you make to these parameters.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10196925" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Unit+Tests/">Unit Tests</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/TFS/">TFS</category></item><item><title>Capturing C++ Code Coverage with Visual C++</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/08/16/capturing-c-code-coverage-with-visual-c.aspx</link><pubDate>Tue, 16 Aug 2011 23:32:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10196431</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10196431</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/08/16/capturing-c-code-coverage-with-visual-c.aspx#comments</comments><description>&lt;p&gt;I wrote an article about six months ago on code coverage in C++, which is part of my article &lt;a href="http://msdn.microsoft.com/en-us/magazine/hh205645.aspx"&gt;Agile C++ Development and Testing with Visual Studio and TFS&lt;/a&gt;. In that article, I showed how to use a command line to create code coverage because I was under the impression that Visual Studio 2010 didn’t support C++ code coverage. I had tried it, but couldn’t get it to work at the time.&lt;/p&gt;  &lt;p&gt;It turns out &lt;strong&gt;there is &lt;/strong&gt;a way to use capture code coverage directly in Visual Studio (or in on a TFS build server) without any customization. The trick, as it turns out, is that you have to turn on the &lt;strong&gt;/Profile&lt;/strong&gt; switch in the linker.&lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h2&gt;Including ALL of your Code&lt;/h2&gt;  &lt;p&gt;If you’re using static libraries, as described in &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx"&gt;Writing Unit Tests in Visual Studio for Native C++&lt;/a&gt;, you will need to make a change to ensure all of your code is included. By default, the linker only includes code from static libraries that is actually used. So if you don’t have a unit test that hits some code, it won’t show up in the code coverage results. That means you won’t be able to find dead code. To fix this problem, you need to turn off linker optimizations:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/4428.image_5F00_75A5C9D7.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/5008.image_5F00_thumb_5F00_1C73E018.png" width="658" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The /OPT:NOREF switch will include all your code in the test DLL.&lt;/p&gt;  &lt;h2&gt;Turning on C++ Code Coverage&lt;/h2&gt;  &lt;p&gt;Right click on your DLL (the test DLL in my case since I use a static library to link the test library into the C++/CLI test project, see &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx"&gt;Writing Unit Tests in Visual Studio for Native C++&lt;/a&gt;) and turn on the /PROFILE linker switch:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0361.image_5F00_0B19176E.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/4555.image_5F00_thumb_5F00_03F9DAF6.png" width="651" height="177" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once you do this, you’ll be able to use the testsettings file to specify which DLLs to instrument. Double-click the testsettings file, click &lt;strong&gt;Data and Diagnostics&lt;/strong&gt;, then click &lt;strong&gt;Code Coverage&lt;/strong&gt; to check the box in the &lt;strong&gt;Enabled&lt;/strong&gt; column:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/5280.image_5F00_0A31778D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/2541.image_5F00_thumb_5F00_30FF8DCD.png" width="640" height="471" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Finally, click &lt;strong&gt;Configure&lt;/strong&gt;, and then check the DLLs that you want to be instrumented, which in this case is the MyCodeTests.dll file that contains both the test code and the product code.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/6354.image_5F00_70C97452.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0081.image_5F00_thumb_5F00_4584DD4B.png" width="623" height="446" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h2&gt;Excluding Test Classes from Code Coverage&lt;/h2&gt;  &lt;p&gt;If you’re using static libraries and C++/CLI for testing as I described in &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx"&gt;Writing Unit Tests in Visual Studio for Native C++&lt;/a&gt;, you may have noticed that your test methods also show up in the code coverage results. You can exclude all the methods in a test class from code coverage using the ExcludeFromCodeCoverageAttribute in front of the class. For example:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestClass]&lt;br /&gt;[ExcludeFromCodeCoverage]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ref &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MyClassFixture&lt;br /&gt;{&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Now all the methods in your test class will be excluded from the code coverage results.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You’ll need SP1 of Visual Studio 2010 in order to see lines colored to show coverage information.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10196431" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Unit+Tests/">Unit Tests</category></item><item><title>Building for Testability in C++</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/07/12/building-for-testability-in-c.aspx</link><pubDate>Tue, 12 Jul 2011 23:37:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10185828</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10185828</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/07/12/building-for-testability-in-c.aspx#comments</comments><description>&lt;p&gt;Ten months ago, when I joined my current team, we had a C++ application that was written as many applications are, with a number of classes, inheritance, and classes creating other classes they needed in order to do their work. The trouble was that writing tests for this code was very hard because it was very difficult to isolate a single class for testing. We had some tests, but they were all written as black-box tests that exercised the UI. Unfortunately, as I mentioned in my blog post on &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/02/11/i-have-a-dream-an-automated-dream.aspx"&gt;No Regressions&lt;/a&gt;, UI tests are hard to write, hard to maintain, run slowly, and are fragile (in other words, small, intentional changes to the product can easily break the UI test).&lt;/p&gt;  &lt;p&gt;In this blog, I’ll describe the architecture that I proposed and then implemented in order to allow us to test at the different levels of the &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/02/11/i-have-a-dream-an-automated-dream.aspx"&gt;pyramid&lt;/a&gt;. We’re dealing with a fairly small codebase (less than 10,000 lines), so we were able to rewrite the program over a period of about six months, while also adding new functionality. As I write this, we have a total of about 1,000 automated tests, divided into roughly 700 unit tests and 300 acceptances/UI tests (written by three people).&lt;/p&gt;  &lt;p&gt;When I set out to build this architecture, I had the goal of being able to write tests in C# that would exercise our C++ code. Most of our unit tests are written in C++/CLI (see &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx"&gt;Writing Unit Tests in Visual Studio for Native C++&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/03/02/c-cli-to-c-tips-and-tricks.aspx"&gt;C++/CLI to C++ Tips and Tricks&lt;/a&gt;) because we didn’t have all the pieces in place to write C# tests until a month or so ago. If I were to do this project again, I think I would have tried to get the C# part working earlier because our testers are more comfortable writing in C# (when we searched for testers, far more have C# than C++ experience). The 300 acceptance/UI tests are written in C#. More importantly, we can write &lt;a href="http://en.wikipedia.org/wiki/Mock_object"&gt;mock&lt;/a&gt; objects in C#.&lt;/p&gt;  &lt;h1&gt;Using C# Mocks with C++ Product Code&lt;/h1&gt;  &lt;p&gt;Think about that last statement, because this is pretty interesting. Our testers can write mocks in C# that replace production C++ components during testing. In other words, it looks something like this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/1205.image_5F00_59539A87.png" width="462" height="321" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;How can you write a mock in C# (or VB.NET) that will replace a C++ component? Using COM (&lt;a href="http://msdn.microsoft.com/en-us/library/ms694363%28v=VS.85%29.aspx"&gt;Component Object Model&lt;/a&gt;). COM has been around for a long time and is used inside Windows by a number of components. Some people dislike COM, and if you’re one of those people, please read on. I chose to adopt the very core of COM, and nothing else. Since .NET interoperates very well with COM, and it’s fairly easy to write COM components in C++, the COM object model acts very nicely as a bridge between the .NET test methods and the C++ product code that we’re testing.&lt;/p&gt;  &lt;h1&gt;Why Choose COM?&lt;/h1&gt;  &lt;p&gt;Why did I chose COM? Basically, because both C++ and .NET support COM. Here is the .NET support for COM that I needed:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;.NET supports calling methods on COM interfaces &lt;/li&gt;    &lt;li&gt;.NET supports writing classes that implement COM interfaces &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;When people think of COM, they don’t always think of the same thing, as there are many different levels (OLE, DCOM, COM++, etc.). But the very core of COM is actually quite simple. Every component supports at least one interface called &lt;a href="http://msdn.microsoft.com/en-us/library/ms680509(VS.85).aspx"&gt;IUnknown&lt;/a&gt; plus one or more other interfaces. And that’s really all there is to the core of COM.&lt;/p&gt;  &lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/ms680509(VS.85).aspx"&gt;IUnknown&lt;/a&gt; interface supports object lifetime through &lt;a href="http://en.wikipedia.org/wiki/Reference_counting"&gt;reference-counting&lt;/a&gt;, and it also has a method, called &lt;a href="http://msdn.microsoft.com/en-us/library/ms682521(v=VS.85).aspx"&gt;QueryInterface&lt;/a&gt;, that allows access to other interfaces supported by the component. Here is the notation that is used for a COM component that supports two interfaces:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/1033.image_5F00_470AD3C5.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0537.image_5F00_thumb_5F00_7902744F.png" width="230" height="132" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This component is a button that implements IUnknown and IControl. All interfaces inherit from IUnknown, so the three methods from IUnknown are always available. I’m not going to go into details on how to implement a COM component in C++ here—there are a lot of resources where you can find that, plus I want to focus on the high-level approach.&lt;/p&gt;  &lt;h1&gt;&lt;/h1&gt;  &lt;h1&gt;Using Private Classes and Class Factories&lt;/h1&gt;  &lt;p&gt;Traditionally C++ applications are written with the class declaration in a header file and the implementation in a “.cpp” file. This allows you to subclass an existing class. However, subclassing can make it more difficult to test classes, particularly when the base class contains implementation that could change and break a number of subclasses.&lt;/p&gt;  &lt;p&gt;I decided to go the pure component route. Using a component model, you can’t subclass a component, nor can you create create a class directly. This approach makes it easier to test and reuse components since dependencies are explicit (I’ll explain dependencies between components in the next section), and it also helps focus design with &lt;a href="http://en.wikipedia.org/wiki/Separation_of_concerns"&gt;separation of concerns&lt;/a&gt; in mind. In this section I’ll focus on using the &lt;a href="http://en.wikipedia.org/wiki/Factory_(software_concept)"&gt;factory pattern&lt;/a&gt;, where you define a public class with a public method for creating a new instance of a component. The class for the component, on the other hand, is private:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/3660.image_5F00_6DD8EA05.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/4331.image_5F00_thumb_5F00_1FD08A90.png" width="380" height="292" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Using this approach has several advantages:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It ensures that no class is dependent on any other class. You can still have dependencies on other components, which is done by using interfaces &lt;/li&gt;    &lt;li&gt;When building a component, you don’t have to flip back and forth between the header and implementation—it’s all in one file. You can have the implementation directly inline instead of having a separate class definition and implementation &lt;/li&gt;    &lt;li&gt;Components are easier to replace with other components, which helps with testability (replacing a component with a mock, for example) &lt;/li&gt;    &lt;li&gt;If a class depends on another component, you’ll need to supply that class to the component. This also make mocking easier &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here is a concrete example of this, showing the full header file, as well as an abbreviated implementation file.&lt;/p&gt;  &lt;h3&gt;&lt;/h3&gt;  &lt;h6&gt;RadioButtonWrapper.h&lt;/h6&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #cc6633"&gt;#pragma&lt;/span&gt; &lt;span style="color: #cc6633"&gt;once&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;IRadioButton.h&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; RadioButtonWrapperFactory&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt;:&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Create(HWND hwndControl, HWND hwndDailog, IRadioButton **ppInstance);&lt;br /&gt;};&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;This is the class factory. Pretty simple.&lt;/p&gt;

&lt;h6&gt;RadioButtonWrapper.cpp&lt;/h6&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;p&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;stdafx.h&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;BaseControl.h&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;RadioButtonWrapper.h&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #cc6633"&gt;#include&lt;/span&gt; &lt;span style="color: #006080"&gt;&amp;quot;UnknownImpl.h&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; RadioButtonWrapper : &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; BaseControl&amp;lt;IRadioButton&amp;gt;&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt;:&lt;br /&gt;    RadioButtonWrapper(HWND hwndControl, HWND hwndDialog) : BaseControl(hwndControl), m_hwndDialog(hwndDialog)&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt;:&lt;br /&gt;    ...&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; EnableRadio(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; id, BOOL enable)&lt;br /&gt;    {&lt;br /&gt;        HWND hWnd = ::GetDlgItem(m_hwndDialog, id);&lt;br /&gt;        ::EnableWindow(hWnd, enable);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; HWND    m_hwndDialog;&lt;br /&gt;};&lt;br /&gt;&amp;#160;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RadioButtonWrapperFactory::Create(HWND hwndControl, HWND hwndDialog, IRadioButton **ppInstance)&lt;br /&gt;{&lt;br /&gt;    *ppInstance = &lt;span style="color: #0000ff"&gt;static_cast&lt;/span&gt;&amp;lt;IRadioButton *&amp;gt;(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; RadioButtonWrapper(hwndControl, hwndDialog));&lt;br /&gt;}&lt;/p&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;I’ve removed all except for one method. As you can see, the component is entirely contained within the CPP file, and therefore completely private. Only the factory is public, and it’s implementation is very simple.&lt;/p&gt;

&lt;h1&gt;Creating a Mock in C#&lt;/h1&gt;

&lt;p&gt;I’ll be filling the details on how to make all this work in some future posts. I also plan to provide a downloadable Visual Studio solution that has all the details working. For now, I’m going to provide a high-level overview of how you would write a mock object in C#.&lt;/p&gt;

&lt;p&gt;There are a few things you’ll need. The interfaces that we use are all defined in header files, but .NET requires an interop assembly. In a later blog post I’ll describe how to create an interop assembly based on the C++ code. For now, let’s assume that assembly exists. Here is an actual mock object from our test suite:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MockCPUCheck : ICpuInfo&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; m_Is64bit;&lt;br /&gt;&amp;#160;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; MockCPUCheck(&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; is64bit)&lt;br /&gt;    {&lt;br /&gt;        m_Is64bit = is64bit;&lt;br /&gt;    }&lt;br /&gt;&amp;#160;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Is64Bit()&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; m_Is64bit ? 1 : 0;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;In this case, ICpuInfo is an interface that was defined in the C++ product code that is present in the interop assembly. To create a mock, all you have to do is subclass from this interface and implement the methods for that interface, which in this case is the method Is64Bit. In the product there is a “real” class that checks to see if the CPU is a 64-bit CPU. But when we’re testing the code with component/acceptance tests, we want some tests pretend to run on a 32-bit machine, and other tests pretend to run on a 64-bit machine.&lt;/p&gt;

&lt;p&gt;When you’re testing a component that expects an ICpuInfo interface, simply create an instance of this class and pass it to the C++ method, which ties into the next section on dependency injection.&lt;/p&gt;

&lt;h1&gt;&lt;/h1&gt;

&lt;h1&gt;Isolating Components with Dependency Injection&lt;/h1&gt;

&lt;p&gt;It can be very hard to test an object that creates other objects because of the tight coupling between the object you want to test, and the objects it creates. &lt;a href="http://en.wikipedia.org/wiki/Dependency_injection"&gt;Dependency injection&lt;/a&gt; is a technique that helps decouple dependencies. The idea is that the caller of a component, rather than the component, is responsible for creating dependent components. The caller creates the other components and then passes them to the component it wants to use. This may seem a little backwards, but it allows test code to provide &lt;a href="http://en.wikipedia.org/wiki/Mock_object"&gt;mock&lt;/a&gt; instead of the real implementations of these required components, thus completely isolating a component during testing.&lt;/p&gt;

&lt;p&gt;To make this more concrete, let’s say you have a component that can use regular expressions to validate the contents of a text box control. But this component, called RegExValidator, uses a shared component called RegEx to actually evaluate the regular expressions. RegExValidator handles reading text from a text box, calling the RegEx methods, and returning status (perhaps including a message). The signature might look something like this:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;HRESULT Init(IRegEx *pRegEx, LPCWSTR pattern);&lt;br /&gt;HRESULT Validate(ITextControl *pText, LPBSTR pMessage);&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Any consumer of RegExValidator is required to call Init before calling Validate. The caller of the Init method is &lt;em&gt;injecting&lt;/em&gt; the dependency on IRegEx into the RegExValidator component.&lt;/p&gt;

&lt;p&gt;In your test code, you would create a mock object that implements IRegEx, called MockRegEx. You test code would create an instance of MockRegEx and then pass this to RegExValidator’s Init method before calling Validate. You can now test RegExValidator isolated from any “real” component, which means your test methods have complete control over the environment in which your tests run. Isolating the components makes it much easier to write tests that pinpoint regressions to a single class, and hopefully a single method.&lt;/p&gt;

&lt;h1&gt;Using a Factory Registry to Inject Dependencies&lt;/h1&gt;

&lt;p&gt;In some of our code, we use a factory &lt;a href="http://martinfowler.com/eaaCatalog/registry.html"&gt;registry&lt;/a&gt; as a way components can obtain dependent components rather than using dependency injection. For example, the RegExValidator could ask the factory registry for the factory that, in turn, creates a new instance of RegEx. Test code can overwrite the registered factory for a specific type so that a component will receive a mock instance when it asks for a new instance.&lt;/p&gt;

&lt;p&gt;This approach is particularly useful for acceptance tests, as apposed to unit tests. Acceptance tests are typically higher-lever tests that exercise parts of the entire application rather than individual components. As a result, the product code, such as RegExValidator described in the previous section, will be created as a result of running the application. Because the test won’t be creating such components directly, you need a way to inject the mock components at a deeper level.&lt;/p&gt;

&lt;p&gt;As an example, our application has code that shows different results on 32- and 64-bit CPUs. But since this code that uses the process type isn’t accessible directly to the acceptance tests, our acceptance tests register a mock class factory with the registry, and this factory returns a mock CPU test:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;MockCPUCheckFactory cpuCheckFactory = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MockCPUCheckFactory();&lt;br /&gt;m_page.Wizard.RegisterFactory(WizardComponents.CpuInfo, cpuCheckFactory);&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;
Now when the code asks for information about the CPU type, it will get this mock component instead of the real component. This means the acceptance tests can validate both 32- and 64-bit results regardless of the actual CPU type.

&lt;p&gt;Here is the definition of the class factory, which implements the &lt;a href="http://msdn.microsoft.com/en-us/library/ms694364(v=VS.85).aspx"&gt;IClassFactory&lt;/a&gt; interface:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MockCPUCheckFactory : WizardTestLibrary.IClassFactory&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; Is64Bit { get; set; }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; CreateInstance(IntPtr pUnkOuter, ref Guid riid, out IntPtr ppvObject)&lt;br /&gt;    {&lt;br /&gt;        ppvObject = Marshal.GetIUnknownForObject(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MockCPUCheck(Is64Bit));&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 0;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; LockServer(&lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; fLock)&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 0;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;I’ll go into more detail in a future post. The main thing to notice here is the call to Marshal.&lt;a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getiunknownforobject.aspx"&gt;GetIUnknownForObject&lt;/a&gt;. This method will return a native IUnknown interface from the C# mock object, which can then be passed back to the native code as an &lt;a href="http://msdn.microsoft.com/en-us/library/system.intptr.aspx"&gt;IntPtr&lt;/a&gt;, which represents a pointer.&lt;/p&gt;

&lt;h1&gt;How do you Make this Work?&lt;/h1&gt;

&lt;p&gt;Obviously, I’ve left out al lot of details in this post. There is some more groundwork I’ll need to lay, which I plan to do in future blog posts. My next blog post, for example, will cover how to define an interface in C++ that will appear in an interop assembly that can be consumed in .NET.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10185828" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Unit+Tests/">Unit Tests</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Acceptance+Tests/">Acceptance Tests</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2300_/">C#</category></item><item><title>Balancing Work By Discipline Instead of Individuals</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/06/02/balancing-work-by-discipline-instead-of-individuals.aspx</link><pubDate>Thu, 02 Jun 2011 20:19:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10170836</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10170836</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/06/02/balancing-work-by-discipline-instead-of-individuals.aspx#comments</comments><description>&lt;p&gt;As part of our effort to become a highly-effective agile team, we’ve been working on switching from an individual to a team focus. During sprint planning, we want to know that we haven’t taken on too much work for each discipline. And on a daily basis, we’d like to see if we’re running behind on a discipline. For example, if we’re running behind on test, are there things developers can do to help?&lt;/p&gt;  &lt;p&gt;The Iteration Backlog workbook that is included in the &lt;a href="http://msdn.microsoft.com/en-us/library/dd380647.aspx"&gt;MSF for Agile Software Development v5.0&lt;/a&gt; process template is a really nice workbook. As implemented, it allows you to see how much work is assigned to each individual so you can tell if they have the right amount of work.&lt;/p&gt;  &lt;p&gt;However, not all agile teams like to assign work up-front to individuals—it’s fairly common to have group ownership of work within a discipline. As a result, I decided to modify the Iteration Backlog workbook to report on discipline rather than individuals. The changes are quite involved, so I’m only going to provide a high-level overview of the changes I made.&lt;/p&gt;  &lt;h1&gt;Overview of Changes&lt;/h1&gt;  &lt;p&gt;If you want to make this type of changes, you’ll want to read my blog post: &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/02/14/customizing-the-iteration-backlog-workbook.aspx"&gt;Customizing the Iteration Backlog Workbook&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Here is a brief overview of the changes I made in order to have the capacity worksheet use discipline rather than team member. First, I needed to add a separate table that maps team members into disciplines:&lt;/p&gt;  &lt;p&gt;Add a new &lt;strong&gt;Team Members&lt;/strong&gt; table to the Settings worksheet:     &lt;br /&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/0844.image_5F00_7F0082C2.png" width="409" height="146" /&gt; &lt;/p&gt;  &lt;p&gt;You can actually add the same person more than once if they’re sharing their time between disciplines. The team member names here can be anything you want—they’re not tied to a field in the query results. The &lt;strong&gt;Discipline&lt;/strong&gt; column, however, is tied to values from the Activity field. You do this by turning on data validation (in the &lt;strong&gt;Design&lt;/strong&gt; tab of the ribbon) and setting the &lt;strong&gt;Source&lt;/strong&gt; field to &lt;strong&gt;=Disciplines&lt;/strong&gt;, which is a named range on the HiddenCapacityData worksheet.&lt;/p&gt;  &lt;p&gt;The Remaining Capacity cells have the following formula:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;p&gt;=&lt;span style="color: #0000ff"&gt;IF&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;AND&lt;/span&gt;(ISNUMBER(IterationStart),ISNUMBER(IterationEnd),ISBLANK([@[Team Member]])=&lt;span style="color: #0000ff"&gt;FALSE&lt;/span&gt;),&lt;br /&gt;    [@[Hours/Day]]*NETWORKDAYS(TODAY(),IterationEnd, Holidays[&lt;span style="color: #0000ff"&gt;Date&lt;/span&gt;])&lt;br /&gt;        - SUMIFS(PlannedInterruptions[Remaining Hours],PlannedInterruptions[Team Member],[@[Team Member]]),&lt;br /&gt;    &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;br /&gt;)&lt;/p&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Modify the &lt;strong&gt;Planned Interruptions&lt;/strong&gt; table so the drop-down list of team members comes from the new &lt;strong&gt;Team Members&lt;/strong&gt; table instead of the &lt;strong&gt;Assigned To&lt;/strong&gt; field of the query results. This change required modifications to the VBA code &lt;/p&gt;

&lt;p&gt;The finished &lt;strong&gt;Capacity&lt;/strong&gt; worksheet looks something like this (I’m using dummy data):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/6354.image17_5F00_11BE374B.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/8311.image17_5F00_thumb_5F00_03138B66.png" width="549" height="344" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;VBA Changes&lt;/h2&gt;

&lt;p&gt;In the sections below I’m going to provide some of the details of changes I made to the VBA code. You’ll need some understanding of working with VBA in Excel in order to be successful following these examples. Because of the large number of changes I had to make to the workbook, I’m not going to provide you with all the details, but rather enough so with some effort on your part, you can get this to work, or perhaps make other types of changes.&lt;/p&gt;

&lt;h3&gt;VBA Changes for the Interruptions Worksheet&lt;/h3&gt;

&lt;p&gt;The interruptions worksheet needs to pull a list of users from the new Team Members table. Here are the changes you’ll need to make to the VBA.&lt;/p&gt;

&lt;p&gt;First, add a new variable definition, m_disciplines, near the top of the file:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; m_users() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; m_disciplines() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; String&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Then at the end of the code, modify the UpdateLists sub, and add a new sub:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; UpdateLists()&lt;br /&gt;    UpdateList FIELD_ACTIVITY, NAME_DISCIPLINE_LIST, m_disciplines, &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;&lt;br /&gt;    UpdateUserList&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; UpdateUserList()&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; r &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Range&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; c &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; Range&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; n &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; name&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; list &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; ListObject&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; columnIndex &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Integer&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; vals &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;New&lt;/span&gt; Collection&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #008000"&gt;'&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;' Build a collection with only the unique values&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;'&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt; list = GetListByName(Settings, LIST_TEAM_MEMBERS)&lt;br /&gt;    &lt;br /&gt;    columnIndex = list.ListColumns(Settings.Range(NAME_TEAM_MEMBER_CAPTION).value).index&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;If&lt;/span&gt; columnIndex = 0 &lt;span style="color: #0000ff"&gt;Then&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Exit&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt;&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Set&lt;/span&gt; r = list.ListColumns(columnIndex).DataBodyRange&lt;br /&gt;    &lt;br /&gt;    &lt;span style="color: #0000ff"&gt;For&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Each&lt;/span&gt; c &lt;span style="color: #0000ff"&gt;In&lt;/span&gt; r.Cells&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;On&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Error&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Resume&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt;&lt;br /&gt;        vals.Add c.value, c.value&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;On&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Error&lt;/span&gt; &lt;span style="color: #0000ff"&gt;GoTo&lt;/span&gt; 0&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Next&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;'&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;' Sort the values we got back&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #008000"&gt;'&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;Dim&lt;/span&gt; sortedVals() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; &lt;span style="color: #0000ff"&gt;String&lt;/span&gt;&lt;br /&gt;    SortCollection vals, sortedVals&lt;br /&gt;    &lt;br /&gt;    UpdateListRange NAME_USER_LIST, sortedVals, m_users&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;h3&gt;VBA Changes for Capacity Worksheet&lt;/h3&gt;

&lt;p&gt;The changes in the code behind the Capacity worksheet involve changing formulas, and also using a list of disciplines instead of people.&lt;/p&gt;

&lt;p&gt;At the top of the file, change m_users to m_disciplines:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Private&lt;/span&gt; m_disciplines() &lt;span style="color: #0000ff"&gt;As&lt;/span&gt; String&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;In the code around line 92 (in the Sub called UpdateFormulas), change the code so it looks like this:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;formula = &lt;span style="color: #006080"&gt;&amp;quot;=IF(ISBLANK(&amp;quot;&lt;/span&gt; + _&lt;br /&gt;          LIST_INDIVIDUAL_CAPACITY + &lt;span style="color: #006080"&gt;&amp;quot;[[#This Row],[&amp;quot;&lt;/span&gt; + FIELD_TEAM_MEMBER + &lt;span style="color: #006080"&gt;&amp;quot;]]),&amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;,&amp;quot;&lt;/span&gt; + _&lt;br /&gt;          &lt;span style="color: #006080"&gt;&amp;quot;SUMIFS(&amp;quot;&lt;/span&gt; + _&lt;br /&gt;          tableName + &lt;span style="color: #006080"&gt;&amp;quot;[&amp;quot;&lt;/span&gt; + FIELD_REMAINING_WORK + &lt;span style="color: #006080"&gt;&amp;quot;], &amp;quot;&lt;/span&gt; + _&lt;br /&gt;          tableName + &lt;span style="color: #006080"&gt;&amp;quot;[&amp;quot;&lt;/span&gt; + FIELD_ITERATION_PATH + &lt;span style="color: #006080"&gt;&amp;quot;], &amp;quot;&lt;/span&gt; + NAME_CURRENT_ITERATION + &lt;span style="color: #006080"&gt;&amp;quot; &amp;amp; &amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;, &amp;quot;&lt;/span&gt; + _&lt;br /&gt;          tableName + &lt;span style="color: #006080"&gt;&amp;quot;[&amp;quot;&lt;/span&gt; + FIELD_AREA_PATH + &lt;span style="color: #006080"&gt;&amp;quot;], &amp;quot;&lt;/span&gt; + NAME_AREA_PATH + &lt;span style="color: #006080"&gt;&amp;quot; &amp;amp; &amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;*&amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;, &amp;quot;&lt;/span&gt; + _&lt;br /&gt;          tableName + &lt;span style="color: #006080"&gt;&amp;quot;[&amp;quot;&lt;/span&gt; + FIELD_&lt;font color="#ff0000"&gt;ACTIVITY&lt;/font&gt; + &lt;span style="color: #006080"&gt;&amp;quot;], &amp;quot;&lt;/span&gt; + &lt;span style="color: #006080"&gt;&amp;quot;[&amp;quot;&lt;/span&gt; + FIELD_TEAM_MEMBER + &lt;span style="color: #006080"&gt;&amp;quot;],&amp;quot;&lt;/span&gt; + _&lt;br /&gt;          tableName + &lt;span style="color: #006080"&gt;&amp;quot;[&amp;quot;&lt;/span&gt; + FIELD_WORK_ITEM_TYPE + &lt;span style="color: #006080"&gt;&amp;quot;], &amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt; + WORK_ITEM_TYPE + &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt; + _&lt;br /&gt;          &lt;span style="color: #006080"&gt;&amp;quot;))&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;
  &lt;br /&gt;&lt;/div&gt;



&lt;p&gt;This changes the formula to group by the Activity field instead of the AssignedTo field.&lt;/p&gt;

&lt;p&gt;Finally, change the UpdateLists sub at the end of the file:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;Public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;Sub&lt;/span&gt; UpdateLists()&lt;br /&gt;    UpdateList FIELD_&lt;font color="#ff0000"&gt;ACTIVITY&lt;/font&gt;, NAME_&lt;font color="#ff0000"&gt;DISCIPLINE&lt;/font&gt;_LIST, m_&lt;font color="#ff0000"&gt;disciplines&lt;/font&gt;, &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #0000ff"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;This will retrieve the unique set of activity values from the query results and update a named range in the hidden CapacityData worksheet. You’ll also need to update the named range in that worksheet, as well as update the set of named ranges in the GlobalConstants module.&lt;/p&gt;

&lt;h1&gt;Using the Discipline Iteration Backlog&lt;/h1&gt;

&lt;p&gt;Using this workbook is very much like using the version shipped with the process template, with some important differences.&lt;/p&gt;

&lt;h3&gt;Enter Team Members&lt;/h3&gt;

&lt;p&gt;First, you’ll need to add your team members to the &lt;strong&gt;Team Members&lt;/strong&gt; table on the &lt;strong&gt;Settings&lt;/strong&gt; worksheet. It doesn’t matter what you type in for each team member. You should, however, ensure that you use unique names for team members (if you don’t, &lt;strong&gt;Planned Interruptions&lt;/strong&gt; won’t behave correctly).&lt;/p&gt;

&lt;p&gt;If a team member is available to work in more than one activity, such as both development and testing, add one line for each combination of team member and activity. That way their time can be shared between activities.&lt;/p&gt;

&lt;h3&gt;Select Disciplines&lt;/h3&gt;

&lt;p&gt;In the &lt;strong&gt;Discipline Capacity&lt;/strong&gt; table, make sure you have one row for each activity that you’re tracking. The rows in this table control what you see in the graphs on this page.&lt;/p&gt;

&lt;p&gt;That’s really all there is to using the Discipline version of the Iteration Backlog workbook.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10170836" width="1" height="1"&gt;</description></item><item><title>Driving Automation of Test Cases</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/06/01/a-test-case-automation-report.aspx</link><pubDate>Thu, 02 Jun 2011 01:37:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10170533</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10170533</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/06/01/a-test-case-automation-report.aspx#comments</comments><description>&lt;p&gt;As I’ve mentioned in previous posts, our team has been working our way up the &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/02/11/i-have-a-dream-an-automated-dream.aspx"&gt;testability pyramid&lt;/a&gt;. We started with unit tests, and now have about 670 &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx"&gt;C++/CLI unit tests&lt;/a&gt; that are testing our C++ code. However, we didn’t have any automated acceptance or UI tests. Our tester was going nuts because he was always behind the curve, and was doing entirely manual testing.&lt;/p&gt;  &lt;p&gt;Starting about two sprints ago (our sprints are two weeks), we finally had both the resources and infrastructure to be able to start automating acceptance tests. I’ll describe our infrastructure in a separate blog post. But once we start write tests, we wanted to know how were were doing. To answer that question, I wrote a Reporting Services report:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/1121.image_5F00_7844BC5D.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/0871.image_5F00_thumb_5F00_380EA2E3.png" width="544" height="349" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can download this report from here: &lt;img alt="Source Code" align="middle" src="http://archive.msdn.microsoft.com/Images/SourceCode.gif" /&gt; &lt;a href="http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=mpsddev&amp;amp;DownloadId=15460"&gt;Test Automation Status.rdl&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The report above is real data from one of our projects. Green is good—it shows how many test cases we’ve automated. &lt;/p&gt;  &lt;p&gt;This report pulls data from the Test Case work item’s &lt;strong&gt;Automation Status&lt;/strong&gt; field. This field can be &lt;strong&gt;Not Automated&lt;/strong&gt; (the default for new test cases), &lt;strong&gt;Planned&lt;/strong&gt;, or &lt;strong&gt;Automated&lt;/strong&gt;. You can switch to automated by clicking on the &lt;strong&gt;Associated Automation&lt;/strong&gt; tab of the Test Case and selecting a test method that is in the currently open solution. Alternatively, if you have the &lt;strong&gt;Test View&lt;/strong&gt; tool window open in Visual Studio, you can right click a test, click &lt;strong&gt;Associate Test to Test Case&lt;/strong&gt; and then choose a test case.&lt;/p&gt;  &lt;p&gt;Since we plan to automate almost all of these test cases, we’re using the &lt;strong&gt;Planned&lt;/strong&gt; automation state to represent test cases where we’re writing an automated test. In other words, in our case, &lt;strong&gt;Planned&lt;/strong&gt; represents work in flight.&lt;/p&gt;  &lt;p&gt;Hope you find this report as useful as we do in both driving test case automation, and knowing where you’re at.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10170533" width="1" height="1"&gt;</description></item><item><title>Fixing Cube Processing ODBC Errors</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/05/27/fixing-cube-processing-odbc-errors.aspx</link><pubDate>Fri, 27 May 2011 18:20:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10169166</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10169166</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/05/27/fixing-cube-processing-odbc-errors.aspx#comments</comments><description>&lt;p&gt;Our Team Foundation Server (TFS) cube has been running just fine. But a couple of days ago, right after we updated the passwords on the service account, it stopped updating the cube. Here I’ll briefly describe how I found the problem, and also what appears to be the fix.&lt;/p&gt;  &lt;p&gt;In order to find the problem, I downloaded the &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-06-17/1348.AdminReportPack.zip"&gt;Admin Report Pack&lt;/a&gt; and installed the Cube Status report. You can find much more information on this report in Grant Holliday’s post: &lt;a href="http://blogs.msdn.com/b/granth/archive/2010/07/12/administrative-report-pack-for-team-foundation-server-2010.aspx"&gt;Administrative Report Pack for Team Foundation Server 2010&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;When I ran this report, I saw error messages like this:&lt;/p&gt;  &lt;p&gt;&lt;font color="#666666"&gt;[Incremental Analysis Database Sync]:      &lt;br /&gt;AnalysisDatabaseProcessingType=Full, needCubeSchemaUpdate=True.       &lt;br /&gt;Microsoft.TeamFoundation.Server.WarehouseException: TF221122: An error occurred running job Incremental Analysis Database Sync for team project collection or Team Foundation server TEAM FOUNDATION.       &lt;br /&gt;Microsoft.TeamFoundation.Server.WarehouseException: Failed to Process Analysis Database 'Tfs_Analysis'.       &lt;br /&gt;Microsoft.TeamFoundation.Server.WarehouseException: Internal error: The operation terminated unsuccessfully.      &lt;br /&gt;OLE DB error: OLE DB or ODBC error: A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.; 08001; Client unable to establish connection; 08001; Encryption not supported on the client.; 08001.      &lt;br /&gt;Errors in the high-level relational engine. A connection could not be made to the data source with the DataSourceID of 'Tfs_AnalysisDataSource', Name of 'Tfs_AnalysisDataSource'.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;It seems to indicate that there is a network-related issue. However, all we did was change the password on the service accounts running TFS and SSAS.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#4f81bd" size="3"&gt;The Solution&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Here is what I did:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Change the service account for Analysis Services from a domain account to Local System.&lt;/li&gt;    &lt;li&gt;Restart SSAS&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;After that, everything started to work just fine. I then set the service account back to the domain account, using the updated password, and everything is continuing to run correctly. What I didn’t try, and what may work just fine, is to simply restart the Analysis Services service. If I run into this error again, I’ll try that fix (I’ve had reports from some other people that restarting the service is enough to fix this problem).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10169166" width="1" height="1"&gt;</description></item><item><title>Building Mixed C# and C++ Projects in TFS 2010</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/05/12/building-mixed-c-and-c-projects-in-tfs-2010.aspx</link><pubDate>Thu, 12 May 2011 17:04:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10163892</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10163892</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/05/12/building-mixed-c-and-c-projects-in-tfs-2010.aspx#comments</comments><description>&lt;p&gt;We recently added C# unit test projects to our existing C++ product and unit test projects, but they weren’t being built by our gated check-ins. I did some research and found lots of blog posts. The closes one, and the blog post that got me pointed in the right directory, was Aaron Hallberg’s post on &lt;a href="http://blogs.msdn.com/b/aaronhallberg/archive/2007/06/25/solution-configurations.aspx"&gt;Solution Configurations&lt;/a&gt;. He talks about the Mixed Platforms custom platform, as well as creating new platform definitions. However, it turns out the solution to our problem was even simpler. All we had to do is check the C# projects so they would be built as part of the Win32 platform:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/6036.image_5F00_6A175921.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/2148.image_5F00_thumb_5F00_5BD8E031.png" width="640" height="401" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;There are two things to notice about this dialog. First, notice that the active platform is set to &lt;strong&gt;Win32&lt;/strong&gt;, and second notice that the &lt;strong&gt;Build&lt;/strong&gt; checkbox is checked for the second project, which is a C# unit test project built using the &lt;strong&gt;Any CPU&lt;/strong&gt; platform.&lt;/p&gt;  &lt;p&gt;Here is the dialog box showing the configurations that are built by our gated check-in build definition on TFS:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/7851.image8_5F00_705E2FAF.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-41-35-metablogapi/7444.image8_5F00_thumb_5F00_30281635.png" width="534" height="396" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In other words, the configurations defined in the build definition need to match up with the configurations you’ve defined in the &lt;strong&gt;solution&lt;/strong&gt; files, not in the project files that are included in that solution.&lt;/p&gt;  &lt;p&gt;We now have both C++ and C# unit tests running as part of gated check-ins. Life is good!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10163892" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Unit+Tests/">Unit Tests</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/-NET/">.NET</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/TFS/">TFS</category></item><item><title>C++/CLI to C++ Tips and Tricks</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/03/02/c-cli-to-c-tips-and-tricks.aspx</link><pubDate>Wed, 02 Mar 2011 18:04:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10136082</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10136082</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/03/02/c-cli-to-c-tips-and-tricks.aspx#comments</comments><description>&lt;p&gt;In my previous post, &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx"&gt;Writing Unit Tests in Visual Studio for Native C++&lt;/a&gt;, I described the approach I’m using to write unit tests for native C++ code by using C++/CLI, which is C++ code that runs inside the .NET runtime. Because of this “mixed” programming model, there are some techniques you may need to employ between C++ and C++/CLI code.&lt;/p&gt;  &lt;h1&gt;Class Instance Variables&lt;/h1&gt;  &lt;p&gt;The instance variables in C++/CLI classes are different from instance variables in native C++, which means you can’t mix the two blindly. For example, you can’t use native C++ classes as instance variables in your test class. The following, for example, will not compile:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ref &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MyFixture&lt;br /&gt;{&lt;br /&gt;    MyClass m_instance;&lt;br /&gt;};&lt;/pre&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;You’ll get the following error message: 
  &lt;br /&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;error C4368: cannot define 'm_instance' as a member of managed 'Tests::MyFixture': mixed types are not supported&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So how do you deal with this? Instead of using a class as the type, you have to use pointers and then create/destroy the instance in the TestInitialize and TestCleanup code:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; ref &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MyFixture&lt;br /&gt;{&lt;br /&gt;    [TestInitialize]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Initialize()&lt;br /&gt;    {&lt;br /&gt;        m_pInstance = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MyClass();&lt;br /&gt;    }&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;    [TestCleanup]&lt;br /&gt;    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Cleanup()&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #0000ff"&gt;delete&lt;/span&gt; m_pInstance;&lt;br /&gt;    }&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;    MyClass *m_pInstance;&lt;br /&gt;};&lt;/p&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;The methods marked by TestInitialize and TestCleanup run before and after each test method.&lt;/p&gt;

&lt;h1&gt;Passing a Pointer to an Instance Variable&lt;/h1&gt;

&lt;p&gt;C++/CLI instance variables have a type of interior_ptr&amp;lt;T&amp;gt; instead of the type you wrote in your code. This makes a difference if you attempt to pass either the address or a reference to this instance variable to a native C++ method or function. For example, given the class above, you might think you could write a call to one of your native methods like this:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;p-&amp;gt;SomeMethod(&amp;amp;m_pInstance);&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Compile this and you’ll see this message:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;error C2664: 'Tests::MyFixture::MyTest' : cannot convert parameter 2 from 'cli::interior_ptr&amp;lt;Type&amp;gt;' to 'MyClass **'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This error appears because .NET uses a heap—items on the heap can be moved as a result of garbage collection. In order to send a pointer to a native method/function, you need to “pin” the pointer for the duration of the call, which you can do like this:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;cli::pin_ptr&amp;lt;MyClass *&amp;gt; p = &amp;amp;m_pInstance;&lt;br /&gt;SomeMethod(&lt;span style="color: #0000ff"&gt;static_cast&lt;/span&gt;&amp;lt;MyClass **&amp;gt;(p));&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Once the variable p either goes out of scope, or is assigned a new value, the pointer will be free to change again.&lt;/p&gt;

&lt;p&gt;When you’re dealing with helper methods in your test code, you can also write this type of code:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;Helper(&amp;amp;m_pInstance);&lt;br /&gt;...&lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Helper(cli::interior_ptr&amp;lt;MyClass *&amp;gt; ppInstance)&lt;br /&gt;{&lt;br /&gt;    **ppInstance = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MyClass();&lt;br /&gt;}&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10136082" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/TDD/">TDD</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Unit+Tests/">Unit Tests</category></item><item><title>Using the Product Planning Workbook with the Scrum Template</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/02/23/using-the-product-planning-workbook-with-the-scrum-template.aspx</link><pubDate>Wed, 23 Feb 2011 18:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10133174</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10133174</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/02/23/using-the-product-planning-workbook-with-the-scrum-template.aspx#comments</comments><description>&lt;p&gt;The Product Planning Workbook does not work with the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/59ac03e3-df99-4776-be39-1917cbfc5d8e/"&gt;Microsoft Visual Studio Scrum 1.0&lt;/a&gt; process template out of the box. Fortunately, it doesn’t take much work to modify the workbook so it will work with the Scrum template.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For information on the Iteration Backlog workbook, see my other post: &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/02/21/using-the-iteration-backlog-workbook-with-the-scrum-template.aspx"&gt;Using The Iteration Backlog Workbook with the Scrum Template&lt;/a&gt;.&lt;/p&gt;  &lt;h1&gt;Create the Product Planning query&lt;/h1&gt;  &lt;p&gt;The existing &lt;strong&gt;Product Backlog&lt;/strong&gt; query is very close to what you’ll need. However, there are two differences, one minor and one not so minor. The not so minor difference is that it needs to show product backlog items that have been closed so it can show you velocity of previous sprints. As a result, I chose to create a new query specifically for this workbook, which you can do by following these steps:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In the &lt;strong&gt;Team Explorer&lt;/strong&gt; window, right click &lt;strong&gt;Product Backlog&lt;/strong&gt;, which is under the &lt;strong&gt;Team Queries&lt;/strong&gt; folder of your team project &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Copy&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Right click &lt;strong&gt;Team Queries&lt;/strong&gt; and click &lt;strong&gt;Paste&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Type &lt;strong&gt;Product Planning – Workbook&lt;/strong&gt; in the &lt;strong&gt;New Name&lt;/strong&gt; text box &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Right click this new query and click &lt;strong&gt;Edit Query&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Above the query results, click on the &lt;strong&gt;Column Options&lt;/strong&gt; button &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Area Path&lt;/strong&gt; in the &lt;strong&gt;Available columns&lt;/strong&gt; list &lt;/li&gt;    &lt;li&gt;Click the &lt;strong&gt;&amp;gt;&lt;/strong&gt; button to add this to the &lt;strong&gt;Selected columns&lt;/strong&gt; list &lt;/li&gt;    &lt;li&gt;Repeat to add the &lt;strong&gt;Activity&lt;/strong&gt; column &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Click on the left side of the clause that excludes the &lt;strong&gt;Done&lt;/strong&gt; state (where you see the right arrow to the left of the selected line):       &lt;br /&gt;      &lt;br /&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/1586.image_5F00_219601E8.png" width="490" height="206" /&gt;       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Click the &lt;strong&gt;Delete Clause&lt;/strong&gt; button (&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/7245.image_5F00_0EE10831.png" width="20" height="15" /&gt;) in the toolbar (at the top, right in the image above) &lt;/li&gt;    &lt;li&gt;Repeat for the &lt;strong&gt;Iteration Path&lt;/strong&gt; clause &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Save Query&lt;/strong&gt; at the top of the query editor window&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Your query results should now contain the Area Path column and show Done product backlog items.&lt;/p&gt;  &lt;h1&gt;Modify the Product Planning Workbook&lt;/h1&gt;  &lt;p&gt;You’ll need to obtain a copy of the Product Planning workbook, which is located in the MSF for Agile Software Development v5.0 process template. You can follow the instruction in my previous blog post on how to retrieve an “unbound” copy of this workbook: &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/02/14/customizing-the-iteration-backlog-workbook.aspx"&gt;Customizing the Iteration Backlog Workbook&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Once you have the Product Planning workbook, here are the instructions on how to modify the workbook:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Press &lt;strong&gt;Alt+F11&lt;/strong&gt; to display the VBA editor &lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Project&lt;/strong&gt; window, click on &lt;strong&gt;LocalizableStrings:&lt;/strong&gt;       &lt;br /&gt;      &lt;br /&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/6663.image_5F00_0E74D53C.png" width="307" height="164" /&gt;       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Properties&lt;/strong&gt; window, click &lt;strong&gt;Visible&lt;/strong&gt; and then select –&lt;strong&gt;1 – xlSheetVisible&lt;/strong&gt; from the drop-down:       &lt;br /&gt;      &lt;br /&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/2061.image_5F00_4E3EBBC1.png" width="305" height="94" /&gt;       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Return to the Workbook and click the &lt;strong&gt;LocalizableStrings&lt;/strong&gt; to display this now visible worksheet &lt;/li&gt;    &lt;li&gt;Change &lt;strong&gt;Story Points&lt;/strong&gt; to &lt;strong&gt;Effort&lt;/strong&gt;, which is probably in cell &lt;strong&gt;B5&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Change &lt;strong&gt;Active&lt;/strong&gt; to &lt;strong&gt;Committed&lt;/strong&gt;, which is probably in cell &lt;strong&gt;C2&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Project&lt;/strong&gt; window, click on &lt;strong&gt;LocalizableStrings&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Properties&lt;/strong&gt; window, click &lt;strong&gt;Visible&lt;/strong&gt; and then select &lt;strong&gt;2 – xlSheetVeryHidden&lt;/strong&gt; from the drop-down &lt;/li&gt;    &lt;li&gt;Save the workbook      &lt;br /&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;h1&gt;Binding to Your Project&lt;/h1&gt;  &lt;p&gt;Now you’re ready to go. You can create copies of this workbook and then bind them to a specific team project. Once you’ve bound the workbook (instructions below), you can’t use the workbook with any other team project.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Click cell &lt;strong&gt;A1&lt;/strong&gt; of the &lt;strong&gt;Product Backlog&lt;/strong&gt; worksheet &lt;/li&gt;    &lt;li&gt;Click on the &lt;strong&gt;Team&lt;/strong&gt; ribbon &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;New List&lt;/strong&gt; in the &lt;strong&gt;Team&lt;/strong&gt; ribbon &lt;/li&gt;    &lt;li&gt;Select your project and click &lt;strong&gt;Connect&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Query List&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Click the drop-down under &lt;strong&gt;Query List&lt;/strong&gt; and select &lt;strong&gt;Product Backlog&lt;/strong&gt; from your team project &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Your worksheet should now be ready to use.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10133174" width="1" height="1"&gt;</description></item><item><title>Using The Iteration Backlog Workbook with the Scrum Template</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/02/21/using-the-iteration-backlog-workbook-with-the-scrum-template.aspx</link><pubDate>Mon, 21 Feb 2011 20:11:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10132348</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10132348</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/02/21/using-the-iteration-backlog-workbook-with-the-scrum-template.aspx#comments</comments><description>&lt;p&gt;Our group has switched over from the MSF for Agile to the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/59ac03e3-df99-4776-be39-1917cbfc5d8e/"&gt;Microsoft Visual Studio Scrum 1.0&lt;/a&gt; process template. We really like the Scrum process template. Particularly now that we’ve fixed the work items so we can resolve bugs and task: &lt;a href="http://blogs.msdn.com/b/aaronbjork/archive/2010/12/17/marking-tasks-and-bugs-as-done-during-a-check-in.aspx"&gt;Marking Tasks and Bugs as “Done” During a Check-in&lt;/a&gt;. However, there is one piece we really miss from our days using the MSF for Agile process template: the Iteration Backlog workbook. In particular, we really miss the capacity page.&lt;/p&gt;  &lt;p&gt;So in this blog post, I’ll show you how you can modify Iteration Backlog workbook to work with the Scrum process template.&lt;/p&gt;  &lt;p&gt;If you plan to use your modified workbook on more than one team project, you should start by read my previous blog post: &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/02/14/customizing-the-iteration-backlog-workbook.aspx"&gt;Customizing the Iteration Backlog Workbook&lt;/a&gt;. This will ensure that any changes you make are “portable.” Otherwise, your modified workbook will be tightly bound to a single team project.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For information on the Product Planning workbook, see my other post: &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/02/23/using-the-product-planning-workbook-with-the-scrum-template.aspx"&gt;Using the Product Planning Workbook with the Scrum Template&lt;/a&gt;.&lt;/p&gt;  &lt;h2&gt;Modifying the Sprint Backlog Query&lt;/h2&gt;  &lt;p&gt;The Iteration Backlog workbook needs a few more columns than are provided in the Sprint Backlog query. You’ll see the following message when you click on the Settings worksheet (or any of the other worksheets):&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font color="#ff0000" size="3" face="Calibri"&gt;&lt;strong&gt;One or more required fields filters are not present in the BurndownData pivot table: Area          &lt;br /&gt;Path, Iteration Path, Completed Work. &lt;/strong&gt;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;ol&gt;   &lt;li&gt;Modify the Sprint Backlog query to include the Area Path and Iteration Path columns      &lt;br /&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;h2&gt;Fixing the Lack of Completed Work&lt;/h2&gt;  &lt;p&gt;The Scrum work items don’t have completed work, which is something I don’t miss as a user of this process template. However, the burndown worksheet requires this field. Furthermore, there is validation code that requires this field be present in order for the workbook to be functional.&lt;/p&gt;  &lt;p&gt;The easiest “solution” to this problem is to hide the burndown worksheet from this workbook (removing it requires a lot more changes). After all, the Sprint Burndown report in the Scrump process template is really nice. I’m going to take that approach:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Press &lt;strong&gt;Alt+F11&lt;/strong&gt; to open the Visual Basic for Applications (VBA) editor &lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Project&lt;/strong&gt; window, expand the &lt;strong&gt;Modules&lt;/strong&gt; folder &lt;/li&gt;    &lt;li&gt;Double-click &lt;strong&gt;UtilityModule&lt;/strong&gt; to open this file &lt;/li&gt;    &lt;li&gt;Remove the following line from the &lt;strong&gt;AreRequiredFieldsPresent&lt;/strong&gt; subroutine:       &lt;br /&gt;&lt;font face="Courier New"&gt;AddIfFieldNotPresent list, FIELD_COMPLETED_WORK&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Burndown &lt;/strong&gt;in the &lt;strong&gt;Project&lt;/strong&gt; window &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Visible&lt;/strong&gt; in the &lt;strong&gt;Properties&lt;/strong&gt; window and select &lt;strong&gt;2 – xlSheetVeryHidden&lt;/strong&gt;, as shown here:       &lt;br /&gt;      &lt;br /&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/5444.image_5F00_0EB120A1.png" width="403" height="196" /&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;That’s basically it. Now the Iteration Backlog, Settings, and Capacity worksheets should behave correctly. If there’s enough interest in getting the Burndown worksheet to work with Scrum, I'll address that in a future post.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10132348" width="1" height="1"&gt;</description></item><item><title>Customizing the Iteration Backlog Workbook</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/02/14/customizing-the-iteration-backlog-workbook.aspx</link><pubDate>Mon, 14 Feb 2011 23:18:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10129256</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10129256</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/02/14/customizing-the-iteration-backlog-workbook.aspx#comments</comments><description>&lt;p&gt;The MSF for Agile process template that ships with TFS 2010 includes a nice Iteration Backlog workbook. Because this is an Excel workbook, it’s completely customizable. However, as far as I know, there isn’t any documentation on how to go about customizing this workbook. The Iteration Backlog workbook contains a fair amount of VBA code, so it may be a bit daunting when you try to make changes. I did much of the development on this workbook when I was in TFS, so I can provide some insight into how best to make changes to this workbook.&lt;/p&gt;  &lt;h1&gt;Getting an Unbound Workbook&lt;/h1&gt;  &lt;p&gt;When you double-click the Iteration Backlog workbook inside one of the team projects, you’re getting a copy of the workbook that has been bound to a specific team project. Once a workbook is bound, it’s very hard to unbind it. How is this important? If you’re only going to be changing the workbook for one team project, it isn’t important. However, if you want to make changes that will work with more than one team project, it’s far easier to make changes to a single unbound workbook, and then bind copies of that workbook to the different team projects.&lt;/p&gt;  &lt;p&gt;Here is how you can get unbound copy of the workbook:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;In &lt;strong&gt;Team Explorer&lt;/strong&gt;, right click the server node. &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Team Project Collection Settings&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Process Template Manager&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;MSF for Agile Software Development v5.0&lt;/strong&gt; to select this process template in the list &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Download&lt;/strong&gt;, select the folder where you’d like to save and click &lt;strong&gt;Select Folder&lt;/strong&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;   &lt;br /&gt;These steps will download the entire process template to a new folder created inside the folder you selected. You’ll find the Iteration Backlog workbook in the following path under the process template’s folder:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Windows SharePoint Services\Shared Documents\Project Management&lt;/p&gt; &lt;/blockquote&gt;  &lt;h1&gt;Preparing the Workbook for Development&lt;/h1&gt;  &lt;p&gt;Now that you have an unbound workbook, there are some steps you’ll need to take in order to temporarily connect the workbook to TFS without actually binding the workbook to TFS. I’m using Office 2010, so the instructions below are for that version of Excel. If you have people who will be using Excel 2007, you should probably use Excel 2007 to modify the workbook just to be safe.&lt;/p&gt;  &lt;p&gt;The first step is to retrieve a set of work items you can use while you’re making changes. You’ll save these as a plain text file to ensure that the workbook you’re changing is not bound to TFS, or that it has links to another workbook.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;From &lt;strong&gt;Team Explorer&lt;/strong&gt;, double-click the &lt;strong&gt;Iteration Backlog&lt;/strong&gt; workbook that is in one of your team projects &lt;/li&gt;    &lt;li&gt;Select the entire table on the &lt;strong&gt;Iteration Backlog&lt;/strong&gt; tab and copy this to the clipboard &lt;/li&gt;    &lt;li&gt;Paste the results into &lt;strong&gt;Notepad&lt;/strong&gt; and save it as a text file &lt;/li&gt;    &lt;li&gt;Quit Excel &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;   &lt;br /&gt;Now open the unbound copy of the &lt;strong&gt;Iteration Backlog&lt;/strong&gt; workbook and follow these steps:&lt;/p&gt;  &lt;h1&gt;&lt;/h1&gt;  &lt;ol&gt;   &lt;li&gt;If you see a security warning, click the Enable Content button:      &lt;br /&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/8765.image_5F00_3E4154CC.png" width="418" height="34" /&gt; &lt;/li&gt;    &lt;li&gt;Open the text file you saved in the previous step in &lt;strong&gt;Notepad&lt;/strong&gt;, select all the text, and copy it. &lt;strong&gt;Note:&lt;/strong&gt; make sure &lt;strong&gt;Word Wrap…&lt;/strong&gt; is not checked under the &lt;strong&gt;Format&lt;/strong&gt; menu in Notepad before you copy the text &lt;/li&gt;    &lt;li&gt;Select cell A1 in on the &lt;strong&gt;Iteration Backlog&lt;/strong&gt; tab and past the text from the previous step. &lt;strong&gt;Note:&lt;/strong&gt; It’s important that you copy the text from Notepad so you’re not pasting in a reference to another workbook. &lt;/li&gt;    &lt;li&gt;With the cells containing the copied text still selected in Excel, click the &lt;strong&gt;Insert&lt;/strong&gt; tab on the ribbon, and then click &lt;strong&gt;Table&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Ensure the &lt;strong&gt;My table has headers&lt;/strong&gt; checkbox is checked and click &lt;strong&gt;OK&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;Press &lt;strong&gt;Alt+F11&lt;/strong&gt; to display the &lt;strong&gt;Visual Basic for Applications&lt;/strong&gt; window &lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Project&lt;/strong&gt; pane, expand the &lt;strong&gt;Modules&lt;/strong&gt; node &lt;/li&gt;    &lt;li&gt;Double-click the &lt;strong&gt;DevelopmentModule&lt;/strong&gt; to display the VBA code for this module:       &lt;br /&gt;      &lt;br /&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/2402.image_5F00_7A00ED7F.png" width="274" height="356" /&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;   &lt;br /&gt;The subroutine inside this module is called &lt;strong&gt;Prepare&lt;/strong&gt;, and it should look like this:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;.Add tableName &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot;_ASServerName&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;, msoPropertyTypeString, &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;br /&gt;.Add tableName &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot;_ASDatabaseName&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;, msoPropertyTypeString, &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;br /&gt;.Add tableName &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot;_TeamProjectName&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;, msoPropertyTypeString, &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;br /&gt;.Add tableName &amp;amp; &lt;span style="color: #006080"&gt;&amp;quot;_TeamProjectId&amp;quot;&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;False&lt;/span&gt;, msoPropertyTypeString, &lt;span style="color: #006080"&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;You will to insert some text inside the “” at the end of each line. Here is a summary of what will need to go into each of those lines:&lt;/p&gt;

&lt;table border="0" cellspacing="0" cellpadding="2" width="644"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="137"&gt;_ASServerName&lt;/td&gt;

      &lt;td valign="top" width="505"&gt;The name of the SQL Server machine that contains your TFS cube. You may have to contact your TFS administrator to determine this name.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="137"&gt;_ASDatabaseName&lt;/td&gt;

      &lt;td valign="top" width="505"&gt;Unless you administrator made any changes, this will be “Tfs_Warehoue”&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="137"&gt;_TeamProjectName&lt;/td&gt;

      &lt;td valign="top" width="505"&gt;The name of your team project&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="137"&gt;_TeamProjectId&lt;/td&gt;

      &lt;td valign="top" width="505"&gt;This is a GUID that you can obtain by right clicking your team project in &lt;strong&gt;Team Explorer&lt;/strong&gt; and selecting &lt;strong&gt;Properties&lt;/strong&gt;. The Url property will contains something that looks like this: vstfs:///Classification/TeamProject/&lt;em&gt;guid&lt;/em&gt;, which &lt;em&gt;guid&lt;/em&gt; will be the value you want to use here.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;
  &lt;br /&gt;Once you’ve made these changes, click anywhere inside the &lt;strong&gt;Prepare&lt;/strong&gt; subroutine and press &lt;strong&gt;F5&lt;/strong&gt; to run this method. Your workbook should now function as if it is bound to TFS without actually being bound (the content on the &lt;strong&gt;Iteration Backlog&lt;/strong&gt; tab is “static” because it’s not actually bound to a TFS query).&lt;/p&gt;

&lt;h1&gt;Sharing the Customized Workbook&lt;/h1&gt;

&lt;p&gt;Once you’ve finished making changes to the workbook, you’ll need to undo the temporary “binding” you setup in the previous section. This is actually very simple. Place the cursor inside the &lt;strong&gt;Clean&lt;/strong&gt; subroutine in &lt;strong&gt;DevelopmentModule&lt;/strong&gt; and press &lt;strong&gt;F5&lt;/strong&gt;. This will set the workbook back to a clean state that you can then put into a process template or share with anyone on your team.&lt;/p&gt;

&lt;p&gt;If you want to bind to an actual team project, make sure you make a copy of the workbook (so you don’t bind your “development” copy). &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Make sure the &lt;strong&gt;Iteration Backlog&lt;/strong&gt; tab is the active tab &lt;/li&gt;

  &lt;li&gt;Click cell A1 to make this the active cell &lt;/li&gt;

  &lt;li&gt;Click the &lt;strong&gt;Team&lt;/strong&gt; ribbon &lt;/li&gt;

  &lt;li&gt;Click &lt;strong&gt;New List&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;Select your team project and click &lt;strong&gt;Connect&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;Select the &lt;strong&gt;Iteration Backlog&lt;/strong&gt; query and click &lt;strong&gt;OK&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
  &lt;br /&gt;Then click the &lt;strong&gt;Team&lt;/strong&gt; ribbon and click &lt;strong&gt;New List&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;When and Why VBA&lt;/h1&gt;

&lt;p&gt;You may be wondering why there is so much VBA in this workbook. And there is quite a bit. In this section I’ll provide an overview of the VBA used by each tab of the workbook.&lt;/p&gt;

&lt;h3&gt;Iteration Backlog Tab&lt;/h3&gt;

&lt;p&gt;The VBA code on this tab runs whenever you switch to this tab. It sets up custom formatting of the State and Remaining Work columns, as shown here:&lt;/p&gt;

&lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/2425.image_5F00_5DF02E94.png" width="318" height="82" /&gt;&lt;/p&gt;

&lt;p&gt;The state has a green background whenever it’s Active. The Remaining Work column shows bars that give you an idea of the size of the different tasks, in terms of the number of hours remaining. You can easily modify these macros to change the formatting to work the way you want.&lt;/p&gt;

&lt;p&gt;If you’ve changed the name of states, you don’t need to modify the macros. Instead, there is a hidden worksheet that contains the list of names. I’ll cover this a little later.&lt;/p&gt;

&lt;h3&gt;Settings Tab&lt;/h3&gt;

&lt;p&gt;The main job of the macros for this tab are to update the validation list used for the Area and Iteration cells. These lists display all the areas/iterations that are present in the query result. The actual code to update these lists is in &lt;strong&gt;UtilityModule&lt;/strong&gt;, and is rather long. Chance are you won’t need to modify these macros.&lt;/p&gt;

&lt;h3&gt;Interruptions Tab&lt;/h3&gt;

&lt;p&gt;The macros on this tab handle updating the team member list (from the Assigned To field on the &lt;strong&gt;Iteration Backlog&lt;/strong&gt; tab) and doing some validation.&lt;/p&gt;

&lt;h3&gt;Capacity Tab&lt;/h3&gt;

&lt;p&gt;This tab is probably where you’ll want to make customizations. There are a number of moderately complex formulas on this page, and many of them are actually set by the VBA code. Why, you ask? The formulas in this tab need to reference the query results table in the &lt;strong&gt;Iteration Backlog&lt;/strong&gt; tab. However, this table doesn’t exist until TFS creates it. Since you can’t have formulas reference something that doesn’t exist, we had to use macro code to setup the formulas. That means any changes you make to the formulas, without updating the VBA code, will be overwritten by the VBA code whenever you switch back to this worksheet.&lt;/p&gt;

&lt;p&gt;The easiest way to modify the formulas is to try making changes directly in the worksheet until you have it working the way you want. Then copy the formula into Notepad, for example. And finally update the VBA code that sets the formulas to use your modified formula.&lt;/p&gt;

&lt;h3&gt;Burndown Tab&lt;/h3&gt;

&lt;p&gt;I would venture to say that the majority of the VBA code in the workbook is devoted to this tab. The burndown chart is driven from a PivotTable on the hidden &lt;strong&gt;BurndownData&lt;/strong&gt; worksheet that is connected to the TFS cube (which is a special type of database designed for historical reporting).&lt;/p&gt;

&lt;h1&gt;Customizing State Names and Other Strings&lt;/h1&gt;

&lt;p&gt;The names of states and fields that are used by macros are stored in a “very hidden” worksheet called &lt;strong&gt;LocalizeableStrings&lt;/strong&gt;. In order to display this worksheet, you’ll need to switch to the VBA editor (press &lt;strong&gt;Alt+F11&lt;/strong&gt;), select &lt;strong&gt;LocalizeableStrings&lt;/strong&gt;, and then change the &lt;strong&gt;Visible&lt;/strong&gt; property to –&lt;strong&gt;1 – xlSheetVisible&lt;/strong&gt;, as shown here:&lt;/p&gt;

&lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/6710.image_5F00_19AFC748.png" width="308" height="518" /&gt;&lt;/p&gt;

&lt;p&gt;You’ll now be able to see that worksheet in the workbook.&lt;/p&gt;

&lt;h1&gt;Summary&lt;/h1&gt;

&lt;p&gt;This blog post just scratches the surface, but I hope it helps people customize the Iteration Backlog (and Product Backlog) workbooks for their own needs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10129256" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Agile/">Agile</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/TFS/">TFS</category></item><item><title>I Have a Dream…No Regressions</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/02/11/i-have-a-dream-an-automated-dream.aspx</link><pubDate>Fri, 11 Feb 2011 16:55:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10128142</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10128142</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/02/11/i-have-a-dream-an-automated-dream.aspx#comments</comments><description>&lt;p&gt;OK, so “I have a dream” isn’t original, and perhaps neither is my dream. However, the path to my dream is the road less traveled, and I believe we should have a super-highway instead of a dirt road.&lt;/p&gt;  &lt;p&gt;Imagine you could build software without fear of breaking existing behavior. That’s my dream. As a developer, I want to be able to constantly improve our architecture to make it easy to add new functionality. But I don’t want to break anything. I don’t want to break the build. I don’t want to break someone else’s code. I don’t want to break the product. And I don’t want to break a customer’s scenario after shipment.&lt;/p&gt;  &lt;p&gt;You may be wondering if this is even possible. I believe it is through a suite of automated regression tests. In our case, it’s mapping &lt;a href="http://blog.mountaingoatsoftware.com/the-forgotten-layer-of-the-test-automation-pyramid"&gt;Mike Cohn’s test pyramid&lt;/a&gt;, which I first encountered while reading the book &lt;a href="http://www.amazon.com/Agile-Testing-Practical-Guide-Testers/dp/0321534468/ref=sr_1_1?ie=UTF8&amp;amp;qid=1297375527&amp;amp;sr=8-1"&gt;Agile Testing&lt;/a&gt;, into the Visual Studio/Team Foundation Server stack. &lt;/p&gt;  &lt;p&gt;Traditionally I’ve heard people say it’s the job of testers to ensure quality. Rubbish. It’s the team’s responsibility. Without developer involvement, it would be very expensive to get to the goal of no regressions. As developers, it’s our job ensure our code is testable. I’ll go into more detail on this later.&lt;/p&gt;  &lt;h2&gt;Path to No Regressions&lt;/h2&gt;  &lt;p&gt;In my experience working on teams, there are several things that lead to regressions and loss of productivity for the team. On one team, we were constantly fighting with build breaks. Before checking in I would get the latest code from source, only to find it wouldn’t build. How frustrating is that. Then once I got it to build, behavior we depended on would be broken, so we’d have to figure out who’s code it was and work with them to get a fix. Double grump. I really don’t want to go through that again.&lt;/p&gt;  &lt;p&gt;Here is a short list of things you can do to prevent this type of problem, which I’ll cover in more detail below:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Gated check-ins&lt;/li&gt;    &lt;li&gt;Suite of automated regression tests&lt;/li&gt;    &lt;li&gt;Failing tests for new bugs&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;At the core of all of this is discipline. Our team has to believe in “No Regressions” and work together to achieve that dream. My job is to help inspire the team to achieve this goal.&lt;/p&gt;  &lt;h2&gt;Automating Regression Testing&lt;/h2&gt;  &lt;p&gt;Automated regression tests should run automatically. No, that’s not redundant. In one team I worked on, it was a huge effort to get the regression tests to run. Testers needed to manually start a test run. And even then, the run often required manual intervention in order to get the tests to run. Ideally a regression suite should run automatically, without any intervention. And the results should be easy to access by anyone on the team.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/8713.image_5F00_4D11EBAE.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/2450.image_5F00_thumb_5F00_25D7A279.png" width="606" height="275" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It’s also important to have the right mix of tests. On the left is a version of Mike Cohn’s test automation pyramid found on p. 277 of the book &lt;a href="http://www.amazon.com/Agile-Testing-Practical-Guide-Testers/dp/0321534468/ref=sr_1_1?ie=UTF8&amp;amp;qid=1297375527&amp;amp;sr=8-1"&gt;Agile Testing&lt;/a&gt;. I’ve modified this slightly. The idea is that each level of the pyramid provides a general idea of how many tests should be at that level. Each unit test should exercise just one public method of a class in isolation, should run in less than 20ms, and should run on any computer. Developers should be writing the tests in the bottom section of the pyramid.&lt;/p&gt;  &lt;p&gt;The upper two levels of the pyramid are generally where testers will create automated regression tests, but we as developers still have a responsibility in these two levels—we need to design and write our code so testers can write tests below the UI, where they can be less fragile and run faster.&lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h2&gt;Stage 1: Unit Tests &amp;amp; Gated Check-Ins&lt;/h2&gt;  &lt;p&gt;Here is where we enter the dream. All of the tests in the pyramid should be run automatically and frequently on servers. Today our team’s unit and component tests run automatically whenever we check code into Team Foundation Server. We’ve set this up with gated check-in turned on. If the build fails, or if any of the unit tests fail, the check-in is rejected. In other words, we don’t have build breaks anymore. Woo hooo!&lt;/p&gt;  &lt;p&gt;Of course, we can still break the product, and we have. This is where the next two layers come into play.&lt;/p&gt;  &lt;h2&gt;Stage 2: Acceptance Tests&lt;/h2&gt;  &lt;p&gt;The next level up is where things get trickier, especially when we’re writing software that works with server software, such as System Center Configuration Manager in our case. Here we want/need to run the tests in a real environment. Of course, this means the tests can have side effects that destroy the integrity of the environment. I once wrote a simple test that ended up corrupting a SharePoint database so you couldn’t even run the administration tools. I had to wipe out the databases and create new ones.&lt;/p&gt;  &lt;p&gt;This is where Visual Studio Lab Management comes into play. You can configure a set of virtual machines in an isolated lab. Once you have this all setup, you can spin off a new isolated lab for each test run. This means you can have several developers/testers running tests or debugging software with “real” environments without stepping on each other (this is big!). You also have a well-known environment each time you spool up a test run. Finally, and this is one that sounds pretty exciting to me as a developer, if a test fails, you can go back to the snapshot of the lab at the point where the test failed, which means you can actually look at the repro environment. Very nice! I want it now!&lt;/p&gt;  &lt;h2&gt;Stage 3: UI Tests&lt;/h2&gt;  &lt;p&gt;The last layer is the smallest because as many of the acceptance/integration tests as possible should be below the UI. UI tests tend to be fragile, slow to run, and hard to maintain. As a result, you want just enough UI tests to ensure that the UI still works. Without support from us developers, testers are usually forced into writing far more UI tests than headless tests below the UI.&lt;/p&gt;  &lt;p&gt;If we take it as a given that we have good testing in the layers below, testers can use Test Manager to create recorded tests that are used as smoke tests. Now imagine that these tests are also run in Lab Management automatically. Wouldn’t it be great if every night the build server would build the latest source and then kick off &lt;strong&gt;all&lt;/strong&gt; of the tests in the pyramid?&lt;/p&gt;  &lt;h2&gt;Stage 4: One Button Delivery&lt;/h2&gt;  &lt;p&gt;I decided to throw in one more goal because I’ve just started to read the book &lt;a href="http://www.amazon.com/Continuous-Delivery-Deployment-Automation-Addison-Wesley/dp/0321601912/ref=sr_1_1?s=books&amp;amp;ie=UTF8&amp;amp;qid=1297375575&amp;amp;sr=1-1"&gt;Continuous Delivery&lt;/a&gt;. The dream here is that you can deliver/deploy quickly and easily with a single button click. Then if anything goes wrong, which is detected automatically, the system automatically rolls back to the last known-good state.&lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h2&gt;Where Next?&lt;/h2&gt;  &lt;p&gt;I don’t know if our small team will realize this dream, but I certainly hope so. I will blog more about our progress towards this dream as we make that progress.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10128142" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Agile/">Agile</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/TDD/">TDD</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Unit+Tests/">Unit Tests</category></item><item><title>Reading and Writing Task Sequence Variables in .NET</title><link>http://blogs.msdn.com/b/jsocha/archive/2011/01/31/reading-and-writing-task-sequence-variables-in-net.aspx</link><pubDate>Tue, 01 Feb 2011 01:44:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10122895</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10122895</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2011/01/31/reading-and-writing-task-sequence-variables-in-net.aspx#comments</comments><description>&lt;p&gt;I’m working on a program that needs to read Configuration Manager task-sequence variables while running in the full operating system (as apposed to Windows PE). Reading task sequence variables is really quite simple. However, all the examples are either in VB Script, or C++. I’m writing this program in C#, so I need a managed way to read task sequence variables.&lt;/p&gt;  &lt;p&gt;First, some background. You can find more information about task-sequence variables is this article on MSDN: &lt;a href="http://msdn.microsoft.com/en-us/library/bb693541.aspx"&gt;About Task Sequence Variables&lt;/a&gt;. The object you need to use is a COM object. C#, as well as other .NET languages, has good support for working with COM objects. However, it’s not always obvious how to reference a COM object in .NET. The normal way is to open the &lt;strong&gt;Add Reference&lt;/strong&gt; dialog box, click the COM section, locate the DLL and then click &lt;strong&gt;Add&lt;/strong&gt;. However, there are cases where this isn’t sufficient, and working with the COM object for task-sequence variables is one of these cases.&lt;/p&gt;  &lt;p&gt;Some COM DLLs, such as the TsCore.dll that we need to reference, have what’s known as an embedded type library. This is a description of the COM objects that are exposed by the DLL. In order to use such a DLL, you need to create an interop assembly that provides a bridge between .NET and COM. This is done using a program called &lt;a href="http://msdn.microsoft.com/en-us/library/tt0cf3sx(v=VS.90).aspx"&gt;TlbImp&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The following command line will run &lt;a href="http://msdn.microsoft.com/en-us/library/tt0cf3sx(v=VS.90).aspx"&gt;TlbImp&lt;/a&gt; and create a new DLL called TsEnvironmentLib.dll:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;quot;%WindowsSdkDir%\Bin\TlbImp&amp;quot;”%SystemRoot%\CCM\TSCore.dll”&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Once you run this command, you can open the &lt;strong&gt;Add Reference&lt;/strong&gt; dialog box, click the &lt;strong&gt;Browse&lt;/strong&gt; button and select TsEnvironmentLib.dll, which is a .NET assembly. At this point, reading a task sequence variable looks something like this:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;TSEnvClassClass ts = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TSEnvClassClass();&lt;br /&gt;&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ts[&lt;span style="color: #006080"&gt;&amp;quot;MyVarName&amp;quot;&lt;/span&gt;];&lt;br /&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;There is one final issue. You need to make sure you use a version of TlbImp that matches the .NET version you’re targeting. In the case above, I needed to use .NET 3.5 since the target machine probably won’t have .NET 4 installed on it. I tried the different versions of TlbImp that were on my computer, and the one in the Windows SDK folder on my computer targets .NET 3.5. You can see which version TlbImp targets by running it without any parameters.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10122895" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/ConfigMgr/">ConfigMgr</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/-NET/">.NET</category></item><item><title>Writing Unit Tests in Visual Studio for Native C++</title><link>http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx</link><pubDate>Fri, 19 Nov 2010 21:14:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10094003</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>30</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10094003</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2010/11/19/writing-unit-tests-in-visual-studio-for-native-c.aspx#comments</comments><description>&lt;p&gt;My team frequently creates wizards that run in Windows PE as part of a Configuration Manager task sequence, and we write them in C++. I’m a big fan of TDD, so when I started to work on a new architecture for our wizards, I wanted to write all the code using TDD.&lt;/p&gt;  &lt;p&gt;When I asked around about writing C++ tests, I was told there isn’t any support for C++ unit tests in Visual C++. Not true. In this blog post I’ll describe what’s required in order to write unit test for native C++ code using Visual Studio.&lt;/p&gt;  &lt;p&gt;For new C++ projects, you can set them up as I’ll describe below. However, for your existing code, you may have to reorganize your project structure before you can start writing unit tests.&lt;/p&gt;  &lt;p&gt;Here is a quick overview of the setup for testing C++ code:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The unit tests need to be written in C++/CLI in order to use the .NET unit test framework &lt;/li&gt;    &lt;li&gt;The code you’re testing should be in a static library that is linked into both your production EXE/DLL, as well as the test DLL &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;   &lt;br /&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-41-35-metablogapi/4162.image_5F00_6682A9B8.png" width="539" height="135" /&gt;&lt;/p&gt;  &lt;h1&gt;&lt;/h1&gt;  &lt;h1&gt;Setting up the projects&lt;/h1&gt;  &lt;p&gt;As I mentioned above, the first step is to setup the projects correctly:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Create a new &lt;strong&gt;Win32 Project&lt;/strong&gt; and select &lt;strong&gt;Static library&lt;/strong&gt; in the &lt;strong&gt;Application Settings&lt;/strong&gt; screen. This is where you’ll add your production code &lt;/li&gt;    &lt;li&gt;Create a second &lt;strong&gt;Win32 Project&lt;/strong&gt; for your production EXE or DLL &lt;/li&gt;    &lt;li&gt;Create a &lt;strong&gt;Test Project&lt;/strong&gt; (in the C++ section of the &lt;strong&gt;Add New Project&lt;/strong&gt; dialog box) &lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Properties&lt;/strong&gt; dialog box for the test project, change the &lt;strong&gt;Target Name&lt;/strong&gt; to the name you want to use for you unit tests. The default is always &lt;strong&gt;DefaultTest&lt;/strong&gt;, rather than the name of the project you just created &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;I’m using Visual Studio 2010, but these instruction will most likely work with prior versions, especially Visual Studio 2008.&lt;/p&gt;  &lt;p&gt;Next we need to link the static library into the test and production projects, and provide both of those projects access to the header files in the static library:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Right click the test project and select &lt;strong&gt;Properties&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Configuration&lt;/strong&gt; combo box, select &lt;strong&gt;All Configurations&lt;/strong&gt; to ensure the changes below are made to both Debug and Release configurations &lt;/li&gt;    &lt;li&gt;Click the &lt;strong&gt;Common Properties&lt;/strong&gt; node and then &lt;strong&gt;Framework and References&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Add New Reference…&lt;/strong&gt;, select the static library and click &lt;strong&gt;OK&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;Click the &lt;strong&gt;Configuration Properties&lt;/strong&gt; node, then click the &lt;strong&gt;C/C++&lt;/strong&gt; node &lt;/li&gt;    &lt;li&gt;Click in the &lt;strong&gt;Additional Include Directories&lt;/strong&gt; property and type something like this (substitute the name of your library project for &lt;em&gt;ProductLibrary&lt;/em&gt;):       &lt;br /&gt;$(SolutionDir)\&lt;em&gt;ProductLibrary&lt;/em&gt;;%(AdditionalIncludeDirectories) &lt;/li&gt;    &lt;li&gt;Change the &lt;strong&gt;Common Language RunTime Support&lt;/strong&gt; property to &lt;strong&gt;Common Language RunTime Support (/clr)&lt;/strong&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;You’ll want to repeat steps 1-6 for your EXE/DLL project.&lt;/p&gt;  &lt;h2&gt;Writing C++/CLI Unit Tests&lt;/h2&gt;  &lt;p&gt;At this point you should be able to build your solution, so the next step if you’re using TDD is to write a test method. If you’ve written test methods in C#, most of this should be familiar to you, although with a different syntax. But if you’re a C++ programmer and you’ve never written C# unit tests, there is a bit of a learning curve. Here I’ll explain enough to get you started.&lt;/p&gt;  &lt;p&gt;Creating a new C++ Unit Test project initially creates a file called UnitTest1.cpp that contains one unit test. I usually delete the extra code and just leave the single test method. If you have a simple class called SomeClass with a method called SomeValue that returns an int, you can write a test that looks like this:&lt;/p&gt;  &lt;div id="codeSnippetWrapper"&gt;   &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[TestMethod]&lt;br /&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShouldReturn1()&lt;br /&gt;{&lt;br /&gt;    std::unique_ptr&amp;lt;SomeClass&amp;gt; pClass(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; SomeClass());&lt;br /&gt;    Assert::AreEqual&amp;lt;&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;&amp;gt;(1, pClass-&amp;gt;SomeValue());&lt;br /&gt;};&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;There are several elements to this test that you may not be familiar with, but you can find full details on MSDN. First is the &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testmethodattribute.aspx"&gt;TestMethod&lt;/a&gt;&lt;/strong&gt; attribute. This identifies the method as being a test method. When you run the tests in Visual Studio, it will run any public methods marked with this attribute.&lt;/p&gt;

&lt;p&gt;Next, notice the use of the Assert class static method called &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.areequal.aspx"&gt;AreEqual&lt;/a&gt;. There are a number of static methods that allow you to validate the results of running a command. Again, you’ll find all of these documented on &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.aspx"&gt;MSDN&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;Some Tips and Tricks&lt;/h2&gt;

&lt;p&gt;The most significant limitation is the lack of &lt;strong&gt;IntelliSense&lt;/strong&gt; in C++/CLI in Visual Studio 2010 (the C++ team plans to correct that in a future release). Fortunately, there is a third-party product called &lt;a href="http://www.wholetomato.com/"&gt;&lt;strong&gt;Visual Assist X&lt;/strong&gt;&lt;/a&gt; from &lt;a href="http://www.wholetomato.com/"&gt;Whole Tomato Software&lt;/a&gt; that brings back &lt;strong&gt;IntelliSense&lt;/strong&gt; to C++/CLI in Visual Studio 2010. I’ve been using this now for a few weeks and I really love it.&lt;/p&gt;

&lt;p&gt;There are some tricks you’ll want to be aware of when you’re using Assert. Because Assert is designed for .NET code, there are some methods that won’t apply, such as IsNotNull, which expects to receive a managed pointer rather than a native pointer. Here are some ways you can deal with this limitation:&lt;/p&gt;

&lt;div id="codeSnippetWrapper"&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;Assert::AreNotEqual&amp;lt;DWORD_PTR&amp;gt;(0, (DWORD_PTR) pClass, &lt;span style="color: #006080"&gt;&amp;quot;Should not be null&amp;quot;&lt;/span&gt;);&lt;br /&gt;Assert::AreEqual&amp;lt;DWORD_PTR&amp;gt;(0, (DWORD_PTR) pClass, &lt;span style="color: #006080"&gt;&amp;quot;Should be null&amp;quot;&lt;/span&gt;);&lt;br /&gt;Assert::IsTrue(pClass == nullptr, &lt;span style="color: #006080"&gt;&amp;quot;Should be null&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Finally, if you want to test a string value returned by a function, you can do something like this:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;Assert::AreEqual&amp;lt;String^&amp;gt;(&lt;span style="color: #006080"&gt;&amp;quot;Expected&amp;quot;&lt;/span&gt;, gcnew String(pClass-&amp;gt;StringValue());&lt;/pre&gt;

  &lt;br /&gt;&lt;/div&gt;

&lt;p&gt;Note in particular the use of &lt;strong&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/te3ecsc8.aspx"&gt;gcnew&lt;/a&gt;&lt;/strong&gt;, which creates a new instance of a managed class. Likewise, you’ll notice the ^ at the end of String in the AreEqual. This tells the compiler that we’re working with a pointer to a managed instance of type String.&lt;/p&gt;

&lt;h4&gt;Update&lt;/h4&gt;

&lt;p&gt;I’ve create a new blog post with more tips and tricks: &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/03/02/c-cli-to-c-tips-and-tricks.aspx"&gt;C++/CLI to C++ Tips and Tricks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For code coverage, see &lt;a href="http://blogs.msdn.com/b/jsocha/archive/2011/08/16/capturing-c-code-coverage-with-visual-c.aspx"&gt;Capturing C++ Code Coverage with Visual C++&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;&lt;/h3&gt;

&lt;h2&gt;Final Thoughts&lt;/h2&gt;

&lt;p&gt;I’ve been using C++/CLI unit tests with native C++ code now for about 1-1/2 months and I find it a really nice environment. I can debug my unit tests just as easily as C# unit tests. At this point I have about 240 tests and they run in about a 1-2 seconds, which means I can easily run all these tests after making changes to ensure I haven’t broken anything.&lt;/p&gt;

&lt;p&gt;After so many years writing in C#, I never thought I would enjoy C++ programming again. I was wrong. Using TDD to write C++ code is almost as nice as writing C# code, and I’m really enjoying the experience.&lt;/p&gt;

&lt;p&gt;I want to thank my colleague Mike Schmidt for getting me pointed in the right direction. He had some C++/CLI unit tests, but they were testing public functions of a DLL. I did some research and added the part of about using a static library, which provides full access to the internals of the code—just the thing you need for writing code with TDD.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10094003" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/C_2B002B00_/">C++</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/TDD/">TDD</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Unit+Tests/">Unit Tests</category></item><item><title>Feature creep, gold plating, and the Product Backlog</title><link>http://blogs.msdn.com/b/jsocha/archive/2010/10/21/feature-creep-gold-plating-and-the-product-backlog.aspx</link><pubDate>Thu, 21 Oct 2010 20:41:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10079130</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10079130</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2010/10/21/feature-creep-gold-plating-and-the-product-backlog.aspx#comments</comments><description>&lt;p&gt;How many times have you been working on a feature only to discover a new scenario that you feel is important, but isn’t included in the estimates for the current sprint? And what did you do? If you’re like most programmers, you probably just wrote the code to handle the scenario.&lt;/p&gt;  &lt;p&gt;If so, you’re experiencing feature creep and/or gold plating. What this really means is that you’re adding code that perhaps should never be in the product. How’s that you ask? Shouldn’t I ensure that I handle all scenarios?&lt;/p&gt;  &lt;p&gt;In a word, no. You see, not all scenarios have the same value to a customer. If you just go ahead and write code for a scenario, you might be supporting a scenario that really isn’t that important. But you’ve actually taken time away from working on what are most likely more important scenarios.&lt;/p&gt;  &lt;p&gt;So what do you do when you find a scenario that you’re not handling? &lt;strong&gt;Add it to the product backlog.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The product backlog represents value that you’d like to add to the product, stacked from the most important to the least important. When you add a new item to the product backlog, it’s a good idea, as a team, to agree on a stack rank value (like 1000) that you’ll use for new items that haven’t been stacked yet. Also assign the user story (or product backlog item) to yourself so the product owner will know who to talk to when they have questions about the importance of your item.&lt;/p&gt;  &lt;p&gt;The idea of agile is to build as much code as you need to deliver the value, but no more. Building more depth into a feature (gold plating) or adding extra features (feature creep) only takes time away from adding more important value. So stay focused on building the minimum code required to satisfy the acceptance criteria for the current sprint, and put all other ideas on the product backlog.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10079130" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Agile/">Agile</category></item><item><title>A Young Agile Team</title><link>http://blogs.msdn.com/b/jsocha/archive/2010/10/16/a-young-agile-team.aspx</link><pubDate>Sun, 17 Oct 2010 04:25:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10076928</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10076928</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2010/10/16/a-young-agile-team.aspx#comments</comments><description>&lt;p&gt;My team is fairly new to agile. During my first week I talked to the PMs and the developers to get a sense as to where we stood and what the issues were. I first asked about user stories. &lt;/p&gt;  &lt;p&gt;Me: “Do you have user stores?”&lt;/p&gt;  &lt;p&gt;B: “Yes. We have these three stories.”&lt;/p&gt;  &lt;p&gt;Hmmm. Three stories. It didn’t take too long to discover that these were epics rather than sprint-sized user stories. I also looked into the tasks and how they were handling/prioritizing the work. Here is what I found:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;They were using two-week sprints. Good. &lt;/li&gt;    &lt;li&gt;They were working on one user story for a number of sprints. Not good. &lt;/li&gt;    &lt;li&gt;Tasks often covered multiple days of work. Not good. &lt;/li&gt;    &lt;li&gt;Developers were checking in at the very end of the sprint. Not good.&lt;/li&gt;    &lt;li&gt;Developers often wrote either more than needed, or not enough. Not good.&lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;&lt;/h1&gt;  &lt;h1&gt;Improving User Stories&lt;/h1&gt;  &lt;p&gt;First, we needed more and smaller user stories. I worked with the PMs to break the existing stories into ones small enough to fit into a single sprint. Ideally we want to have 4-6 user stories in a sprint. The format I like to use for a user story is based on the Behavior Driven Development (BDD) community:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Title       &lt;br /&gt;&lt;/em&gt;&lt;strong&gt;In order to&lt;/strong&gt;&lt;em&gt; business value&lt;/em&gt;      &lt;br /&gt;&lt;strong&gt;As a &lt;/strong&gt;&lt;em&gt;role&lt;/em&gt;      &lt;br /&gt;&lt;strong&gt;I want to&lt;/strong&gt; &lt;em&gt;feature&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The common format for user stories is pretty close to this: “As a &lt;em&gt;role&lt;/em&gt; I want to &lt;em&gt;feature&lt;/em&gt; so that &lt;em&gt;business value&lt;/em&gt;.” So why change the order? There are several reasons. First, and most importantly, leaving the business value until last means that it’s all to easy to leave it out entirely. I’ve seen many user stories that are really just restatements of features. For agile teams, the business value should be the most important thing because it’s what we exist to deliver. So placing the business value first means you have to write it. Writing the business value is hard, and it takes some practice to learn how to be good at it. But when you do focus on the value first, you’ll often discover that you end up with a very different feature than you had in mind when you first started. That’s a good thing, because it means you’re reacting to the value, not to the feature.&lt;/p&gt;  &lt;p&gt;We use Team Foundation Server to store all of our tasks and user stories. We place the main part of the story in the description field. But you don’t want to have to read the entire story when you’re trying to stack rank user stories—it’s just too hard to scan a long story. The title, therefore, is a short-hand for the entire story, something like a short feature description.&lt;/p&gt;  &lt;h1&gt;Acceptance Criteria&lt;/h1&gt;  &lt;p&gt;Next I worked with the teams to add acceptance criteria to the user stories. User stories tend to be somewhat abstract, so they leave a lot of room for interpretation. This, of course, leads to problems when a developer builds something and says they’re done, but someone else says “but you didn’t handle this.” Acceptance criteria makes a user story concrete. If your story is about performance, and performing an operation needs to be fast, the acceptance criteria defines what “fast” means. For example, it might say that response time needs to be less than 2 seconds. That’s measureable and testable.&lt;/p&gt;  &lt;p&gt;Acceptance criteria also helps constrain the work so you don’t build too much either. This last part is a little hard for programmers to get used to. For some reason, as programmers we think we have to cover all case we can think of. However, all cases may not have equal business value. Good acceptance criteria focuses just on what’s important for this particular user story. If other cases are important, add more user stories on the backlog to cover those cases.&lt;/p&gt;  &lt;p&gt;When do you add acceptance criteria to a user story? There are a couple of pieces to this answer. First, acceptance criteria should be in user stories that are going to be in the next sprint. The product owner needs to spend time preparing for the next sprint by working on the acceptance criteria. Often they’ll involve the testers, who in the agile world are customer advocates. But that doesn’t mean the acceptance criteria need to be complete before the sprint planning meeting.&lt;/p&gt;  &lt;p&gt;During the sprint planning meeting, the acceptance criteria helps the team have a very focused discussion about what done means for a user story, which helps the team do a better job of estimating the size of the user story. The acceptance criteria will most likely be modified or extended as a result of these discussions.&lt;/p&gt;  &lt;p&gt;Testers usually really like the acceptance criteria because they can start to write test cases right away. In fact, each line in the acceptance criteria often maps directly into one or more test cases. Having the test cases early also means programmers can use them to guide the work they do (we’re not there yet as a team).&lt;/p&gt;  &lt;h2&gt;&lt;/h2&gt;  &lt;h1&gt;Working in Stack Rank Order&lt;/h1&gt;  &lt;p&gt;In the next sprint, we had much better user stories, so we were able to have five user stories in a single sprint for one project (we have three projects). While watching the team during the standups, I noticed that they were not focusing on completing user stories in stack rank order. They looked at the list of tasks and chose one to work on. I’ve been reading the book &lt;a href="http://www.amazon.com/Coaching-Agile-Teams-ScrumMasters-Addison-Wesley/dp/0321637704/ref=tmm_pap_title_0"&gt;Coaching Agile Teams&lt;/a&gt; by Lyssa Adkins and she recommended that a coach (which is the role I was playing at the time) sit back and let the team succeed or fail on their own. So I sat back and watched.&lt;/p&gt;  &lt;p&gt;When we got to the sprint review the team had only finished one of the five user stories. They were almost finished with the other four, but each had tasks not yet completed. I had the feeling that they were about to pat themselves on the back for finishing most of the work. When I pointed out that they had only finished one user story and had to return the other four stories to the backlog, you could hear a pin drop. They were not happy.&lt;/p&gt;  &lt;p&gt;This “failure” turned into a win for the team. During the next sprint they really focused on doing the work in stack-rank order, and they paid a lot more attention to finishing one story before moving on to the next.&lt;/p&gt;  &lt;h1&gt;A Regular Cadence&lt;/h1&gt;  &lt;p&gt;To say that the testers were being squeezed is an understatement. When developers waited until the end of the sprint to check in their work, there is no way the testers could possibly test anything until the next sprint. As a result, testing was constantly one sprint behind. So my next goal was to get developers to check in more frequently. Ideally I felt they should check in at least after they finish each task, but at worst when they finish a user story.&lt;/p&gt;  &lt;p&gt;When we tried this in a sprint, the tester was very happy because he was able to start testing early in the first week, and by the end of the sprint he had tested much of the work done during the sprint. Success!&lt;/p&gt;  &lt;h1&gt;One Month Later&lt;/h1&gt;  &lt;p&gt;In just one month, we’ve gotten to the point where:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;We have sprint-sized user stories.&lt;/li&gt;    &lt;li&gt;We have more user stories, and the backlog is now growing on a regular basis as we think of things that should be in the product&lt;/li&gt;    &lt;li&gt;The acceptance criteria is helping the team build just enough, and no more&lt;/li&gt;    &lt;li&gt;The testers a much better understanding of what we’re going to build&lt;/li&gt;    &lt;li&gt;Testers are able to test much earlier in the sprint, and can test during the sprint&lt;/li&gt;    &lt;li&gt;User stories are being implemented in stack rank order&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;We’re by no means done learning how to do all of this well, but the team has made a lot of progress in a short time. I’m glad we’re using two-week sprints because this learning curve would have been slower if we had longer sprints.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10076928" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/Agile/">Agile</category><category domain="http://blogs.msdn.com/b/jsocha/archive/tags/User+Stories/">User Stories</category></item><item><title>A New Job, a New Journey</title><link>http://blogs.msdn.com/b/jsocha/archive/2010/10/16/a-new-job-a-new-journey.aspx</link><pubDate>Sun, 17 Oct 2010 00:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10076901</guid><dc:creator>John Socha-Leialoha - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/jsocha/rsscomments.aspx?WeblogPostID=10076901</wfw:commentRss><comments>http://blogs.msdn.com/b/jsocha/archive/2010/10/16/a-new-job-a-new-journey.aspx#comments</comments><description>&lt;p&gt;On September 13, 2010, I started a new journey. This was my first day as an official Microsoft employee, and my first day in a new group, MPSD (Managed Platform and Service Delivery), which is a part of System Center. Before this I spent almost 5 years as a vendor here at Microsoft—first as a subject matter expert on mobile development in the patterns &amp;amp; practices group. And then the last 3-1/2 years as a developer in the process team of Team Foundation Server. It was quite a ride, and I’m very proud to&amp;#160; have been part of the team that built Team Foundation Server 2010. You can find my blog posts about the work I did there at this location: &lt;a title="http://blogs.socha.com/" href="http://blogs.socha.com/"&gt;http://blogs.socha.com/&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;So what caused me to switch to a completely different product and a different team? Agile. And my new team found me—they were looking for a senior developer to help them be more agile, and with development practices. I’d been wanting for a while to be involved in making a highly effective agile team, and this appeared to be a chance for me to do just that.&lt;/p&gt;  &lt;p&gt;I plan to blog about agile, and also about development. I’m a long-time developer, and I love building applications that customers use, so in addition to agile practices, I’ll also be blogging about programming—both in C# and C++. Before coming to this team, it had been nearly 12 years since I last did any serious C++ development. And since I learned C#, I thought I’d never again enjoy C++. Well, I was wrong, and I’ll have more to say about that in a future blog.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10076901" width="1" height="1"&gt;</description></item></channel></rss>
