TFS 2012 Quick Note: How to add text formatting and line breaks to the DEFAULT text of a work item field

This is a quick note so that I can find this in the future. Smileimage

What:

There are times when you want modify a work item so that the value of an HTML string field, like the Description field on a Requirement, has some default value when a new work item is created. You may also want to put some formatting on some or all of this text.

I was working with a customer that wanted to have a “template” for data security that would help the Business Analysts be more consistent in their requirement documentation. We added some bold template text that would be used as a reminder.  The BA would just add the field name and security requirements in plain text next to the defaulted labels.

SNAGHTMLb8342

How:

To get this effect we set the DEFAULT rule on the underlying HTML field to a string of HTML that will get rendered at runtime.  There are two ways that you can enter the HTML to be rendered, through the Process Template Editor or directly within the work item type definition file.  Please note the caveat at the end of this article so you don’t get burned by a limitation of the work item definition schema.

Using the Process Template Editor

When using the Process Template Editor you need to create a DEFAULT rule for your field. In the FROM field select “value” and in the VALUE field you enter your HTML fragment.  In this editor you can enter your HTML just like you would in Visual Studio.  When you hit OK to close the DEFAULT dialog it will escape all of the special characters in the HTML fragment.

SNAGHTML1632e2

Editing the Work Item Type Definition directly

If you edit the work item type definition directly, you have to escape all of the “special” characters so that they don’t interfere with the raw XML surrounding them.  When uploaded to TFS, the escaped entries will be converted to HTML tags that can be rendered at runtime.

 1: <FIELD name="Security" refname="MyCompany.Security" type="HTML">
 2:  <DEFAULT from="value" value="Field Name: 
Security: 

Field Name: 
Security: "
/>
 3: FIELD>

Caveat

There is one thing that really limits the usefulness of this technique.  There is a limit of 255 characters in the value attribute of the DEFAULT element.  This limit is imposed when you import the work item type definition into the team project, so you have to be aware of this when using the Process Template Editor as the text entered there will be escaped on save and could easily go over the character limit.

Community TFS Report Extensions open-source reports hits v1.0 milestone

Microsoft ALM MVP Tommy Norman and I have been working on creating a set of reports that fill some of the gaps in the TFS 2010 out-of-box process templates.  The output of this effort is the Community TFS Report Extensions project on Codeplex which was started this past summer but has finally become stable enough to reach the v1.0.0 milestone.

Tommy has crafted a nice write-up on his blog, so please pop over there and take a look then head on over to the project and check out the first two reports.

 

TestPlanStatusReport

Figure 1 – Test Plan Status report

 

SNAGHTML90acb5

Figure 2 – Release Plan report

VS 2012 – Coded UI Tests (CUIT) Now Automatically Closes Browser or App Upon Test Completion

VS2012Logo

Synopsis

  • Microsoft changed the behavior of Coded UI Tests between Visual Studio 2010 and Visual Studio 2012.
  • The change is that the browser window or app window being used for the test case will automatically be closed after each test case unless you add code to keep it open.
  • In any event, the browser window or app window used will always be closed at the end of a test run.
  • During development you can use a Breakpoint to halt test execution prior to the windows being closed.

Issue

There is a behavior change between Coded UI Tests (CUIT) running in Visual Studio 2010 and Visual Studio 2012 .  In Visual Studio 2010, a test case would leave windows open on the desktop unless they were explicitly closed in code in the test class.  In Visual Studio 2012 , the window of the application under test (browser, WPF app, etc.) is automatically closed whether or not it was closed in code during the test run.  If you are new to CUIT and you only use VS 2012 then you weren’t aware that the behavior changed.  If you have upgraded from VS 2010 then this is something new.

Why did the folks at Microsoft make this change?

This change was added to make it easier to create an maintain test cases because it saves you from explicitly having to close your app window or browser at the end of every test. An automated test run that has many test cases launching browser windows but never closing them will leave the test client’s desktop in a messy state.  I agree that it makes CUIT easier.

So why write a blog post about something you agree with?

The reason for this post is that it changes the way that folks from VS 2010 interact with coded UI tests, specifically if you use a manual test’s Action Recording as the starting point for your CUIT.
In VS 2010 I would create a new CUIT and use the action script from a manual test case to generate a base test without any validation as in the code below. I’d then run this test to make sure everything worked as expected.  At the end the browser would close.

[TestMethod]
public void KioskSmokeTest()
{
 this.UIMap.StartDinnerNowKiosk();
 this.UIMap.ExerciseUI();
 this.UIMap.CloseKiosk();
}

Figure 1: Basic coded UI test that explicitly closes the app under test

Now I need to add some validation to my test.  Normally I would just comment out the line that closes the windows, in my example this.UIMap.CloseKiosk() and re-run the test.  This would leave the app window open and the app would be in the correct state for me to add validations.

[TestMethod]
public void KioskSmokeTest()
{
 this.UIMap.StartDinnerNowKiosk();
 this.UIMap.ExerciseUI();
 //this.UIMap.CloseKiosk();
}

Figure 2: Basic coded UI test that is supposed to leave the app window open at the end

My example is fairly simple, but what if the ExerciseUI() method actually navigated through 4 or 5 screens and added test data. In this case, my process has allowed the test to perform all of the data entry and I am assured that the app is in the correct state for my validations.  This saved me a lot of work and headaches.

In VS 2012, this behavior isn’t the same.  The CloseKiosk() method is no longer needed as the test engine will automatically close the app between test cases unless told to keep them open.  In effect, the first code example is now equivalent to the second one.

 

But I liked the old behavior, is there a workaround?

Your only option is to set a breakpoint on the last executable line within your test case and then go to Test View and right-click on the test’s name then select Debug Selected Tests.  When the breakpoint gets hit, press F10 to let the last executable line run then just stop debugging.  That will leave your app in the correct state and you can now use the Coded UI Test Builder to create your Assertions.

SNAGHTML1fe8b15b

 

Figure 3: Use a breakpoint and debug your test to get to the right app state for validation

SNAGHTML1fe63578

 

Figure 4: Stop debugging when you have finished execution of all of the preparatory steps

 

What if I chain test cases together and assume that the app stays open between tests?

Some folks write completely self-contained tests like my KioskSmokeTest above.  Other folks have more complex needs and write tests that get run in a specific order, each collaborating to setup the state of a system and then performing validations. This can be called “chaining tests”.

If you have chained tests, the new behavior will break your test runs since the application under test gets closed after each test case is run.  Microsoft has added some new flags that can be set (depending on app platform) to tell the test engine to leave your app alone between tests cases in a single test run.

If your target app is browser-based, you can tell the testing framework to leave the browser open at the end of the test case by setting the BrowserWindow.CloseOnPlaybackCleanup property to false (Line 5 below).

 

[TestMethod]
public VerifyValidDefaultSearchTest()
{
 //Leave the browser open
 this.UIMap.UIDinnerNownetWindowsIWindow
 .CloseOnPlaybackCleanup = false;

 this.UIMap.StartvalidsearchParams
 .UIDinnerNownetWindowsIWindowUrl = 
 "http://WebTest/DinnerNow/Default.aspx";
 this.UIMap.Startvalidsearch();
 this.UIMap.ClicktheFindbutton();
}

Figure 5: Use CloseOnPlaybackCleanup to keep the browser open

The Microsoft Visual Studio ALM team has a nice blog post describing this in more detail.

If your target app is not browser-based (WPF/WinForms/etc.) then you need to use the ApplicationUnderTest.CloseOnPlaybackCleanup() property.
Note: There is a bug in VS 2012 RTM that causes ApplicationUnderTest.CloseOnPlaybackCleanup() property to be ignored.  This bug is fixed in VS 2012 Update 1.
Unfortunately the ApplicationUnderTest object isn’t as easy to access as the BrowserWindow objects.  To make this work you will have to capture the instantiation of your app in the UIMap.Designer.cs file and store the reference in a variable that can be seen from your test methods.

Below you see the code that was generated in the UIMap for my application.  This code launches the DinnerNowKiosk application and uses a local variable to store the handle to the app.  Once the StartDinnerNowKiosk method goes out of scope, the reference is no longer accessible.  Also, you can’t just go and add a call to dinnerNowKioskApplication.CloseOnPlaybackCleanup = false because this is a generated code file so the added code will be lost of the UIMap is regenerated.

 

public void StartDinnerNowKiosk()
{
 ApplicationUnderTest dinnerNowKioskApplication = 
 ApplicationUnderTest.Launch
 (this.StartDinnerNowKioskParams.ExePath,
 this.StartDinnerNowKioskParams.AlternateExePath);
}

 

Figure 6: The generated application launch code in the UIMap.designer.cs file

Instead you have to use the UIMap.cs partial class to add your new startup code.  Just copy the StartDinnerNowKiosk() method into the partial class and set the CloseOnPlaybackCleanup property to false.

 

public partial class UIMap
{
 static ApplicationUnderTest dinnerNowKioskApplication_persistent = null;

 public void StartDinnerNowKiosk_Persistent()
 {
 if (null == dinnerNowKioskApplication_persistent)
 {
 dinnerNowKioskApplication_persistent = ApplicationUnderTest.Launch 
 (this.StartDinnerNowKioskParams.ExePath,
 this.StartDinnerNowKioskParams.AlternateExePath);
 dinnerNowKioskApplication_persistent.CloseOnPlaybackCleanup = false;
 }
 }
}

 

Figure 7: The new app launch code from the non-generated partial class in the UIMap

And then change your test to call the new app launcher method.

 

[CodedUITest]
public class KioskSmoke
{

 [TestMethod]
 public void KioskSmokeTest()
 {
 this.UIMap.StartDinnerNowKiosk_Persistent();
 this.UIMap.ExerciseUI();
 }

 [TestMethod]
 public void KioskSmokeTest2()
 {
 this.UIMap.StartDinnerNowKiosk_Persistent();
 this.UIMap.AdditionalSteps();
 }
}

 

Figure 8: The updated tests that call to the new app launcher.

In the example above, the StartDinnerNow_Persistent() method is called from each test case because we don’t know the order these test will be run. If you need to have the tests run in a specific order then you need to create an additional test method that calls them in the order desired.

 

Can I keep the app under test open between test runs?

No.  The app/browser is launched by the test agent process (QTAgent).  At the end of a test run QTAgent is shut down, so any child processes are also shut down. I have confirmed this behavior in VS 2012 RTM and VS 2012 Update 1.

 

Resources

MSDN: BrowserWindow class – http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.browserwindow.aspx

MSDN: ApplicationUnderTest class – http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.applicationundertest.aspx

MSDN:

 

Visual Studio 2012 Update 1 Download – http://www.microsoft.com/en-us/download/details.aspx?id=35774

Visual Studio 2012 ALM Blog: Coded UI Test: Why does application close after each test in Visual Studio 2012? – http://blogs.msdn.com/b/visualstudioalm/archive/2012/11/08/using-same-applicationundertest-browserwindow-across-multiple-tests.aspx

Team Foundation Service is open to the public (and free!)

SNAGHTML80a046dThe Visual Studio Team has hit another major milestone in the evolution of Team Foundation Server.  Back at the BUILD conference last year they announce a hosted TFS offering called Team Foundation Service.  This hosted solution brings TFS based Work Item Tracking, Version Control and Automated Build through a browser and is connectable from Visual Studio just like an on-premises deployment of Team Foundation Server.  Use of the service was limited to those few that were able to get their hands on an Invitation Code.  This was done primarily to allow for a slow ramp-up in users of the service to help find and remedy scalability problems.

“Since we announced the Team Foundation Service Preview at the BUILD conference last year, we’ve limited the onboarding of new customers by requiring invitation codes to create accounts.  The main reason for this has been to control the growth of the service to make sure it didn’t run away from us and end up with a bad user experience.  In this time period, we’ve continued to work on our infrastructure, performance, scale, monitoring, management and, of course, some cool new features like cloud build. ”   – Brian Harry

Today, Brian Harry announced that there is no longer the need for an Invitation Code.  The Service is now open to the Public.  This means that they are confident in the service’s ability to handle the load as well as their ability to monitor activity and upgrade the service with little disruption to the global user community.

They are still offering the service without charge and while they get the final pieces in place to offer a complete commercial service.

“The service will remain in “preview” for a while longer while we work through additional features like data portability, commercial terms, etc but the terms of service support production use, the service is reliable and we expect to carry all of your data forward into production. ”  – Brian Harry

Brian has an excellent walk-through on how to get access to the service and begin playing with the service, the cloud-hosted build servers and the new Azure continuous deployment features.

Brian’s complete post can be found at http://blogs.msdn.com/b/bharry/archive/2012/06/11/team-foundation-service-preview-is-public.aspx

How do I know if I have all of the Visual Studio 2010 Updates?

QuestionMarkWhenever I go to a customer site to perform a TFS installation or upgrade, one of the questions I invariably get from the IT team is “What has to be installed on everyone’s machines to use TFS?  I currently keep a list of handy-dandy blog posts and OneNote notes updated to answer just this question.

Other folks in the TFS space have also come across this question.  One of then, Terje Sandstrom (Visual Studio ALM MVP), has decided to do something about it.  He has written a tool that helps answer this question.  Best of all, it is a Visual Studio plugin.

You can read about this tool on his blog.

After reading his blog I followed the link to the Visual Studio Gallery to do the installation. Once installed, I fired up Visual Studio 2010 and used the new Help | Version Info menu item.

SNAGHTML23786ed3

It brought up a dialog that shows the status of the Visual Studio installation on my development laptop.

SNAGHTML23796e85

Hmmm…

Looks like I’m a bit behind the times.  Luckily Terje has added a link to the update I’m missing which is the Visual Studio 2010 SP1 Team Foundation Server 11 Compatibility GDR.

After a quick install, I re-ran the Version Info tool and voila, I’m up to date on Visual Studio 2010!

SNAGHTML238445ff

Thanks to Terje for creating this handy little add-in.

Question mark pic by Leo Reynolds.