Sunday, March 27, 2011

TFS 2010 - hexadecimal value 0x07 is an invalid character

I recently encountered an issue where my tests in lab management were getting aborted. I really had a hard time figuring out what was really going wrong. I looked into the test run log in the Test Manager->Analyze Test Runs but nothing obvious showed up. I also enabled diagnostic logging in my lab build definition but again nothing showed up.
I then used tcm.exe and created a new test run using "tcm run /create". Then I executed the run using "tcm run /execute" and I got the error: "hexadecimal value 0x07 is an invalid character"
Then I looked into the intellitrace logs in "%localappdata%"\VSEQT\QTController. Here I found that there was an invalid xml in my Assert statement.
Fixing the xml in the Assert solved my problem.

Why http://localhost does not work?

I encountered an issue recently where I was able to browse the Default Web Site using http://IPAddress but was not able to browse it using http://localhost
The reason for that was the Default Web Site Bindings.
If you click on Default Web Site, then click Bindings on the Actions pane, you will see the Site Bindings. Edit the Bindings and in the IP Address drop down, select "All Unassigned" instead of a specific IP Address.

Tuesday, March 8, 2011

TFS 2010 Build: Keep folder tree structure

There are two approaches :
=============================================
Approach 1
=============================================

To keep the output structure, you have to make TFSBuildHost not pass OutDir
to MSBuild and  custom the output path of each project.
  1. Open the build process file, navigate to Compile the Project Sequence, edit the property of Run MSBuild for Project Activity.
    • Set OutDir to empty (just make the textbox is empty)
    • set CommandLineArguments to String.Format("/p:SkipInvalidConfigurations=true {0} /p:TeamBuildOutDir=""{1}""", MSBuildArguments, outputDirectory)
  2. Modify each project file in the solution.
    • Check out project file to Edit.
    • Open project file  with notepad.
    • Find <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    • Use following code to replace the default OutputPath Property.
                   <OutputPath Condition=" '$(TeamBuildOutDir)'=='' ">bin\release\</OutputPath>
                   <OutputPath Condition=" '$(TeamBuildOUtDir)'!='' ">$(TeamBuildOutDir)\<ProjectName>\</OutputPath>
                  The word “Release|AnyCPU” is dependent on the value of “ConfigrationToBuild”  in   TFSBuild.proj.      
    • Save project file and check in.
=============================================
Approach 2
=============================================
  1. Open the build process file, navigate to Compile the Project Sequence, edit the property of Run MSBuild for Project Activity.
  2. Set OutDir to empty (just make the textbox is empty)
  3. Set OutDir to System.IO.Path.Combine(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(localProject))
  4. In the build definition, instead of specifying a single solution, specify the projects individually

Monday, March 7, 2011

TFS 2010 Deployment Items - Prefer DeploymentItem attribute

There are multiple ways to configure deployment items when working with TFS 2010. Lets have a look at them one by one.

Local.testsettings
You can specify the deployment items in the Deployment section of Local.testsettings
Visual studio by default picks up the testsettings while running the tests.
If you are using command line, then you will nedd to pass the /testsetting parameter to mstest
If you are running your tests as part of build process, you need to specify the Local.testsettings in the build definition.

Lab Manager TestSettings
If you are running the test as part of lab process, then the Visual Studio testsetting is not used. You will need to create a test setting in lab manager and the files that are specified should be present on the test controller or be under a shared location.
To use this testsetting, you will have to specify it as part of your test plan or lab build definition.

DeploymentItem Attribute
The best way to make your tests work under all circumstances without making any changes is to use the DeploymentItem attribute on your test class/method.
No matter how you are running your tests, the deployment items will always be copied to the test execution folder.

TFS 2010 TCM - Importing the test cases along with the Area and Iteration paths

With tcm.exe, you can import test cases from your test code. You can pass the test assembly to tcm and it will create new test cases or update existing test cases for each TestMethod. The command for importing the test cases is:

tcm testcase /import /collection:teamprojectcollectionurl /teamproject:project
             /storage:path
             [/maxpriority:priority]
             [/minpriority:priority]
             [/category:filter]
             [/syncsuite:id [/include]]
             [/login:username,[password]]

Also refer http://msdn.microsoft.com/en-us/library/ff942471.aspx

Consider a scenario where you created 10 TestMethods and use tcm to import the test cases. 10 new test cases are created in this case.
You realize that you need to update the Area property of these test cases. Hence you open them in excel and update the Area in one shot.
Now you add 5 more TestMethods and use tcm to import the test cases. 5 new test cases are created in this case. Howevere, along with creating new test cases, the older 10 test cases are updated and the Area property is reseted. So you have to again open all the test cases in excel and update the Area.

In order to make sure that your new test case get the Area assigned while they are imported and you dont loose the Area of exisitng test cases, you can add the following attribute to the TestMethods:
[CssProjectStructure("vstfs:///Classification/Node/<guid>")]
 You can find the guid from Tfs_Warehouse
select AreaGUID from DimArea where AreaPath='...'

Similarly, if you want to update the Iteration, you can use
[CssIteration("vstfs:///Classification/Node/<guid>")]
You can find the guid from Tfs_Warehouse
select IterationGUID from DimIteration where IterationPath='...'

Similarly, you could add other supported attributes to the TestMethods to make sure that they are imported.

TFS 2010 Test Controller - Workaround for TestRunStorage issue

When worked with Test Controller for lab management in TFS 2010, you might have experienced that you start running out of disk space soon. The reason for that is the test results keep accumulating at the path C:\Users\<Account>\AppData\Local\VSEQT\QTController\TestRunStorage

Even if you do the following in MTM (Lab Center -> Controllers -> Right click on controller -> Delete
temporary files), the files in TestRunStorage are not deleted.

To get around this issue, you can create a batch file with the following command:
rmdir /s /q "C:\Users\...\AppData\Local\VSEQT\QTController"

Then create a scheduled task which calls this batch file once every day at
a specific time when no tests would run.

TFS 2010 Build- Running unit tests with code coverage enabled on signed assemblies

For signed assemblies, running unit tests with code coverage enabled requires the key file (*.snk, *.pfx) to be specified in the "Code Coverage Detail" tab in the testsettings.

This works fine when you run the tests locally in Visual Stuio. The problem occurs when you try to use this testsettings in the TFS Build. The specified path of the key file is absolute rather than relative. Hence the key file isnt found during the build.

The solution to the problem is:
Suppose your solution directory is C:\TestSolution and your key file is present at C:\TestSolution\TestProject\Key.snk
Open the testsetting in notepad and instead of specifying the full key path, specify TestProject\Key.snk