以编程方式将现有共享步骤与测试用例相关联

Associate existing shared steps with a test case programmatically

我正在尝试向使用

创建的测试用例添加共享步骤
CreateWorkItemAsync()

创建测试步骤并添加到测试用例中没问题

ITestStep testStep1 = testBase.CreateTestStep();

但我正在尝试将现有的共享步骤添加到测试用例中。我无法在 Azure Devops SDK 中找到这样做的方法。

有一个 ISharedStepReference 接口用于从测试用例调用共享步骤集。

您应该能够将共享步骤添加到特定测试用例中。供您参考的代码片段:

ITestManagementService testService = tfsCollection.GetService<ITestManagementService>();
ITestManagementTeamProject teamProject = testService.GetTeamProject(teamProjectName);

//find test case by testcase id
ITestCase testcase1 = teamProject.TestCases.Find(192); //192 is the testcase id

//find share steps by sharedstep id
ISharedStep sharedStep1 = teamProject.SharedSteps.Find(140); //140 is the shared step id

//Add shareSteps to the specific test case
ISharedStepReference sharedStepReference = testcase1.CreateSharedStepReference();
sharedStepReference.SharedStepId = sharedStep1.Id;
testcase1.Actions.Add(sharedStepReference);
testcase1.Save();

我最后做的是使用

创建测试用例
 CreateWorkItemAsync()

然后使用

获取该工作项
GetWorkItemAsync()

然后编辑字段

Microsoft.VSTS.TCM.Steps

as xml 并将我自己的节点插入适当的位置以将共享步骤添加到测试用例。您可以通过使用 API GET 请求获取测试用例并查看 Microsoft.VSTS.TCM.Steps.

的格式来查看共享步骤的格式