【发布时间】:2016-11-28 16:18:16
【问题描述】:
我正在尝试像其他字段一样更新字段步骤
testCase.Fields["field"].Value = "value";
但更改后仍为空。 如何修改测试用例中的步骤?
【问题讨论】:
我正在尝试像其他字段一样更新字段步骤
testCase.Fields["field"].Value = "value";
但更改后仍为空。 如何修改测试用例中的步骤?
【问题讨论】:
测试用例与 Bug 或 Task 等正常工作项不同。您需要使用 Microsoft.TeamFoundation.TestManagement.Client 中的“ITestManagementService”来更新测试用例。检查下面的代码以供参考:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
namespace TFSDownloadFile
{
class Program
{
static void Main(string[] args)
{
string url = "http://tfscollectionurl/";
TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(url));
ITestManagementService itms = ttpc.GetService<ITestManagementService>();
ITestManagementTeamProject itmtp = itms.GetTeamProject("YourProject");
//Get test case with test case id
ITestCase itc = itmtp.TestCases.Find(1);
//Get the first step in test case
ITestStep teststep = itc.Actions[0] as ITestStep;
//Update the test step
teststep.Title = "New Title";
teststep.ExpectedResult = "New ExpectedResult";
//Save the updated test case
itc.Save();
}
}
}
【讨论】:
您需要使用 Actions 属性。这将返回一个TestActionCollection,您可以使用它来更新这些步骤。您可以对集合中的每个操作使用ITestStep 接口来更新每个步骤的 Title、Description 和 ExpectedResult。不要忘记在工作项上致电Save()。
【讨论】: