Posts

TFS API: Get list of associated work item from work item of any type

I have been observing most of users reported and looking for a way to list out associated work item linked to parent work item. Generally, when we associated work item to another work item - it simply attach it as Link irrespective link type. We can achieve this using TFS Client Side Object model (API). Below is high level code snippet which will fetch all the links associated with work item. // Connect to the server and the store.  TfsTeamProjectCollection  teamProjectCollection = new TfsTeamProjectCollection(collectionUri); //Get the work item service workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore)); // Define a query that uses a variable for the type of work item.  string queryString = string.Format("Select * From WorkItems where Id = {0}",workItemId); // Create and run the query. Query query = new Query(workItemStore, queryString); WorkItemCollection results = query.RunQuery(); foreach(WorkItem wt in results) {    

Associate Test Case Automation using TFS API

Hello, I have been observing most of users reported that associating automation to test case one by one from Visual Studio Team Explorer is tedious job rather time consuming. I was thinking what if we could achieve this using TFS object model. My idea was fetch test case one by one and associate automation to test case and save test case work item. Resolution: Here is code which can use to associate automation in bulk -  Add below references -  Microsoft.TeamFoundation Microsoft.TeamFoundation.Client   Microsoft.TeamFoundation.WorkItemTracking.Client Microsoft.TeamFoundation.WorkItemTracking teamprojectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(collectionUri); workItemStore = projectCollection.GetService<WorkItemStore>(); //You can either specify work item query to fetch test cases WorkItemCollection workItemCollection = workItemStore.Query(      " SELECT * FROM WorkItems " +      " WHERE [System.TeamProject] = '" +

TFS API: Get Work Item History Revisions for parituclar Field

Image
Hello, I observed many of us struggling to view history for any work item. History is visible but it is hard to visualize changes made like who made changes, to which field and when etc. For this matter, one has to scroll through entire history tab and find it tedious job. I was thinking what if we could view work item history for selected field with other details like who changed it and when. Here is solution - I have created a tool which show work item history for selected field. Also shows how may times selected field changed. You can view history by selecting single work item and also export entire work item query history to excel. I find this tool useful so thought of sharing with others. How it works - 1. Run EXE 2. Prompt you select/add team project server details 3. Populates your My Queries to Treeview 4. Double Click query from tree and it will show work items in right grid 5. Select Work item field from top drop down for which you want to see history 6. Doubl

TFS API: How to get latest test result for a test case

We can retrieve test results for particular test case using TFS API. That's straight forward and there are in build methods. I find people asking for how they can retrieve latest test result for particular test case and I got it solved so thought of sharing here. below code snippet will illustrate how to - 1. Connect to TFS Server/Collection/team project Uri tfsUri = new Uri( "http://servername:8080/tfs/collectionname" ); teamProjectCollection = new TfsTeamProjectCollection(tfsUri);   iTestManagementService = teamProjectCollection.GetService<ITestManagementService>(); tfsConnectedTeamProject = iTestManagementService.GetTeamProject( "Team Project Name" );   2. Once connected to TFS server, call APIs to get test results for any particular test case. Below line of code will get all results associated with passed test case Id and this returned list is not sorted var testResults = tfsConnectedTeamProject.TestResults.ByTestId(52737); 3. W

How to: Add users to list of code reviewer in TFS 2012

With TFS 2012 Update 2, we have new feature where we can enable code review in TFS itself. Here are steps to add users to reviewer list. 1. Open TFS Team Web Access 2. It will open in Overview mode 3. In Right side pane, there are options like ACTIVITIES, MEMBERS, ADMINISTRATION 4. ADMINISTRATION link is for Sprint management. 5. For user management - Click on Top Right Setting symbol [Next to Help link] 6. Select Project and select your team Left side panel. Here you can add users you want to. There is Add  button on top. you can add single user or user(s) group. Also you can add multiple Administrators. 7. Once done re-open VSTS and connect team explorer. 8. Create new review request and you will see added user(s) in reviewer list. Thanks,

Automated Test Run Error: There is no test with specified id {GUID}

Those who use Microsoft Test Manager to run their automation, find this error common and some time irritating. As the error states, it unable to find specific test case in associated build to test plan. There may be other reason for this such as - 1. Change in class name spaces but didn't updated automation association 2. Build assigned to test plan is not correct or old one 3. Missing test assemblies in assigned build Resolution: 1. Check if your test assemblies are there in the build drop folder 2. Remove the automation association and re-associate automation method reference. 3. Get the test case ID and make sure it is part of test suite in test plan. 4. Check if associated automated test name is correct. Error states that you are running your test against build which doesn't have associated test in it. 5. Queue new build and once succeeded - assign it to your test plan and make sure this build has all tests which are associated with your automation.  Thanks,

How To: Bulk upload Test Case results to Microsoft Test Manager

Problem Definition: Most TFS or Microsoft Test Manager users find it difficult to update test execution result to MTM. Assume that you are done with 100+ test case execution manually and now you want to upload results (Pass/Fail/Block) for all those test cases and also link bugs, test cases to result as needed. Doing this manually is very time consuming. At this time there is no way to support this ask in MTM versions but yes, we can achieve this by writing our own code using TFS SDK APIs. Resolution: I came along with this issue some time back and created a tool using TFS APIs which upload results to MTM very smoothly. Here is how my tool works:   1. Run tool exe  2. Connect to team foundation server you want to  3.  Select test plan -> Test Suite  4. Click Get Test Case button  5. This will create excel with test cases from selected test suite.  6. There is filter if you want to upload results specifically for manual or automated or all test cases  7.  Open created excel and