Posts

Showing posts from 2013

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

SQL Server Interesting Fact

Just try out this DECLARE @ AS INT SET @= 6 PRINT @ What you think by looking code? Isn't it throw an error....but that's true internally '@' is treated as variable so it will show you output as normal variable. Just try it..

Add attachment to Test Case Result using TFS API

We can add attachment to test case result using TFS APIs. Here is small code snippet I have created. ITestRun testRun = _plan . CreateTestRun ( false ); ITestCaseResultCollection results = testRun . QueryResults (); ITestIterationResult iterationResult ;   foreach ( ITestCaseResult result in results ) {      result . Attachments . Add ( new Attachment ( "FileName" , "Comments if any" )); }   results . Save ( true ); testRun . Save (); testRun . Refresh ();

Create Test Case Step Result using TFS API

We can create test case step result using TFS APIs. Here is small code snippet I have created. ITestRun testRun = _plan . CreateTestRun ( false ); ITestCaseResultCollection results = testRun . QueryResults (); ITestIterationResult iterationResult ;   foreach ( ITestCaseResult result in results ) {     iterationResult = result . CreateIteration ( 1 );        foreach ( ITestStep testStep in result . GetTestCase (). Actions )       {              ITestStepResult stepResult = iterationResult . CreateStepResult ( testStep . Id );              stepResult . Outcome = TestOutcome . Passed ; //you can assign different states here        iterationResult . Actions . Add ( stepResult );       }       iterationResult . Outcome = TestOutcome . Passed ;       result . Iterations . Add ( iterationResult ); }   results . Save ( true ); testRun . Save (); testRun . Refresh ();

Making changes to Child Test suite 'State' will affect the Test plan 'State'?

This question confuses many of us who use MTM for test case management. Curious how state of Test Plan , Test Suite works? Making changes to Child Test suite 'State' will affect the Test plan 'State'? Answer is No. Changes to Child Test suite 'State' won't affect the Test plan 'State'. Test Plan contain one or more different test suites. State of Test Plan are: Active: If Test Plan is set to active which mean that you can run test cases from child test suites of test plan. Inactive: If it is inactive then you cannot run test from its test suites. you can only view, edit test suites. And yes State of Test Plan do affects its child test suites.  State of Test Suite are: In Planning: Test Suite is not ready to run In Progress: Test Suite is ready for use/execution Completed: Test Suite execution completed Test Suite states won't affect Test Plan. Test Suite state should be In Progress to run test from it. If you delete Test Plan then

How to use TFS solutions and working with source control

Many team/people face issues while working TFS project solutions. How to check in, checkout and get latest and so on. There are basic and main steps to take care of: Make sure solution checked in properly. you can confirm this with 'View Pending Changes' option. Also all solution files/projects should be bound to source control. All other users should always get solution/projects from TFS only. I mean always use get latest before you start working on any file. 1. Go to same or some other machine OS 2. Open VSTS and Connect to TFS Team Server 3. Double click Source Control option and select your solution folder 4. Map it to local folder. This will prompt you if you want to get it from TFS server. Say Yes 5. And you should be good here. When you add your solution to source control first  time, VSTS asks to choose checkout policies or you can configure it later. If you want your team to work on same solution, I mean same file can be shared among different users then fo