我已分配创建C#应用程序以更新MTM中的测试用例状态。
我尝试了下面的代码,它运行正常。但问题是以下代码正在更新结果如果测试用例已经执行,则不会更新新创建的测试用例的状态(没有运行历史记录)
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();
}
}
}
有人帮我这个。