Force Visual Studio to think TFS is offline

Visual Studio 2008 introduced a feature that detects where the current Team Foundation Server is online or offline when you start the IDE.

In the situation where your server is actually ONLINE, but you want to treat it LIKE it’s offline, you have a couple of options.

Option 1 - Use the ‘tfpt tweakui’ utility

You can edit the server setting and go offline.

  • Close Visual Studio
  • Download and install the latest Team Foundation Power Tools
  • Start a Visual Studio Command Prompt
  • Type: tfpt tweakui
  • Open the server
  • Check the [X] Server is offline checkbox
  • Open Visual Studio

tfpt tweakui dialog

Option 2 - Yank the network cable before starting Visual Studio

Obviously the IDE won’t be able to contact the server, and will inform you that it is now offline.

Option 3 - Set a registry key

Create a *.reg file with the following text in it, and run it before starting Visual Studio.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\Servers\SERVERNAME]

"Offline"=dword:00000001

"AutoReconnect"=dword:00000000

When you want to go back online, you can either go to "File | Source Control | Go Online", or delete this registry key.

TFS Build: Running Integration Unit Tests

If you’re doing a deployment out to a test server as part of your Continuous Integration build process, you may have some unit tests (or web/load tests) to run after the deployment. Since these tests are testing more than just an assembly, they can be considered integration tests.

This can easily be accomplished by modifying your TFSBuild.proj script. Start by overriding the AfterDropBuild or similar MSBuild target and calling the <TestToolsTask> with the correct parameters.

First of all, you’ll need to define the tests that you want to run. The simplest way is to create a Test List called “Integration Tests” that gets saved in your test metadata file (*.vsmdi).

<ItemGroup>

  <IntegrationTestList Include=”$(SolutionRoot)\src\MySolution.vsmdi”>

    <TestList>Integration Tests</TestList>

    <FlavorToBuild>Release</FlavorToBuild>

    <PlatformToBuild>Any CPU</PlatformToBuild>

  </IntegrationTestList>

</ItemGroup>

There are two additional properties that we need to set, they are the Platform and Flavor. The reason for this is that when MSTest.exe tries to publish the integration test results to TFS, it needs to know what platform/flavor build to build against. And since we are doing this in AfterDropBuild, the configuration information isn’t available.

If your application requires additional files, or extra test run settings, you will need to specify them with a Test Run Config file:

<PropertyGroup>

  <RunConfigFile>$(SolutionRoot)\src\MySolution.testrunconfig</RunConfigFile>

</PropertyGroup>

And finally we can override the AfterDropBuild target to run the test list:

<Target Name=”AfterDropBuild”>

  <!– Execute Integration tests against remote server. –>

  <TestToolsTask

    Condition=” ‘$(IsDesktopBuild)’!=’true’ and ‘%(IntegrationTestList.Identity)’!=””

    BuildFlavor=”%(IntegrationTestList.FlavorToBuild)”

    Platform=”%(IntegrationTestList.PlatformToBuild)”

    PublishServer=”$(TeamFoundationServerUrl)”

    PublishBuild=”$(BuildNumber)”

    SearchPathRoot=”$(OutDir)”

    PathToResultsFilesRoot=”$(TestResultsRoot)”

    MetaDataFile=”%(IntegrationTestList.Identity)”

    RunConfigFile=”$(RunConfigFile)”

    TestLists=”%(IntegrationTestList.TestList)”

    TeamProject=”$(TeamProject)”

    TestNames=”$(TestNames)”

    ContinueOnError=”true” />

</Target>

Now when you view the Team Build results, you will have two sets of Test Results published against the single build.

Query and Update Quality Center Requirements from C#

HP’s Quality Center (QC) is primarily used for it’s defect tracking and test suite management capabilities. More recently they have released a Requirements Management module that is able to tracks requirements.

If you want to query and update the data programmatically, it’s actually quite simple using what they call their “Open Test Architecture” APIs.

  • Add a reference to: C:\Program Files\Common Files\Mercury Interactive\Quality Center\OTAClient.dll

To get this dll on your machine, you’ll need to have logged in to the QC web interface and installed the ActiveX objects.

Then you can query all Requirements by using TDAPIOLELib.ReqFactory.NewList(optional filter):

TDAPIOLELib.TDConnection connection = new TDAPIOLELib.TDConnection();

connection.InitConnectionEx(”http://SERVER:8080/qcbin“);

connection.Login(”USERNAME”, “PASSWORD”);

connection.Connect(”QCDOMAIN”, “PROJECT”);

TDAPIOLELib.ReqFactory reqFactory = connection.ReqFactory as TDAPIOLELib.ReqFactory;

TDAPIOLELib.List requirementsList = reqFactory.NewList(”");

foreach (TDAPIOLELib.Req req in requirementsList)

{

  // View / Modify the properties

  // req.ID, req.Name, etc.

  // Save them when done

  // req.Post();

}

Querying Defects is much the same, just substitute ReqFactory for BugFactory. Enjoy.

Update: And to create new ones, you have to call reqFactory.AddItem(Nothing) in VB, or req.Additem(System.DBNull.Value) in C#.

What’s your Circle of Interest?

Paul Stovell put out the question to bloggers to define how they spend their time. He defines the three areas like this:

Core
These are things I enjoy, care about, and follow as much as I can. When news breaks in these areas, I try to stay on top. I like to think I’m an expert in some of them, and have strong opinions on the rest.

Non-core
I find myself working with these things, or have a minor interest in them, but tend to follow announcements occasionally. I have opinions and will probably complain if I don’t like certain aspects of them, but I’m not about to start evangelising them.

I don’t care
The only time I spend in these things is to decide whether I care or not. I don’t really use them. I don’t pay much attention to them. I prefer not to work in any of these areas.

So here’s what mine looks like at the moment. I have no doubt that some things will get shifted around over the next 12 months while drinking from the firehose, but it’s good to write down where I stand now.

 Circle of Interest

What’s in your circle of interest?