I assigned the creation of a C # application to update the state of the test case in MTM.
I tried the code below and it works fine. But the problem is that the code below updates the result. If the test case has already been completed, it does not update the status of the newly created test case (without start history).
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.WorkItemTracking.Client; using Microsoft.TeamFoundation.TestManagement.Client; using Microsoft.TeamFoundation.TestManagement.Common; using System.IO; namespace UpdateTFS { class Program { static void Main(string[] args) { //args[0] = TestplanId; args[1] = TestcaseId; args[2] = Status; args[3] = configuration int test_plan = Int32.Parse(args[0]); int test_case = Int32.Parse(args[1]); int test_config = Int32.Parse(args[3]); int result_updated = 0; TextWriter tw = new StreamWriter(@"C:\Users\*\Desktop\MTM.txt", true); tw.WriteLine("Attempting the test case " +test_case+ "to be marked as "+args[3]); //Create TFS connection TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName("<tfs_url>")); ITestManagementService tms = tfs.GetService<ITestManagementService>(); //Connect to the project ITestManagementTeamProject proj = tms.GetTeamProject("<project>"); ITestPlan Plan = proj.TestPlans.Find(test_plan); if (Plan != null) { ITestCase tc = proj.TestCases.Find(test_case); if (tc != null) { ITestPointCollection points = Plan.QueryTestPoints("SELECT * FROM TestPoint WHERE TestCaseId =" + args[1]); foreach (ITestPoint p in points) { var testResults = proj.TestResults.ByTestId(test_case); foreach (ITestCaseResult result in testResults) { if (p.ConfigurationId == test_config) { if (args[2] == "Failed") { result.Outcome = TestOutcome.Failed; } else if (args[2] == "Passed") { Console.WriteLine("Passed"); result.Outcome = TestOutcome.Passed; } else if (args[2] == "NotExecuted") { result.Outcome = TestOutcome.NotExecuted; } result.Save(true); result_updated = 1; tw.WriteLine("Test case ID =>" + test_case + "is marked as " + args[2] + "MTM"); } } if (result_updated == 1) { break; } } if (result_updated == 0) { tw.WriteLine(args[3] + " => Configuration is not found in the test case " + test_case); } } else { tw.WriteLine(args[1] + " Test case not found the plan"); } } else { tw.WriteLine(args[0] + " Plan not found in MTM"); } tw.Close(); } } }
anyone help me with this.
source share