我试图在Visual Studio中使用c#在TFS中创建类型为测试用例的工作项。我可以设置除“ steps”字段以外的所有其他字段的值。如何设置步骤字段的值?
我尝试了workitem.Fields["steps"].value = "value"
,但是没有用。
答案 0 :(得分:0)
那是行不通的,因为您必须使用对TestManagement Client的引用。然后获取您的测试用例并添加如下新步骤:
TfsTeamProjectCollection tfs;
tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(uri));
tfs.Authenticate();
ITestManagementService service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));
ITestManagementTeamProject testProject = service.GetTeamProject(project);
ITestCase testCase = TestProject.TestCases.Find(1);
ITestStep newStep = testCase.CreateTestStep();
newStep.Title = "New Step Title";
newStep.ExpectedResult = "New Step Expected Result";
testCase.Actions.Add(newStep);
查看以下链接:
答案 1 :(得分:0)
请注意,Steps
字段是html
类型。您可以尝试使用REST API设置步骤的值。一个例子如下:
POST https://xxxx.visualstudio.com/{teamproject}/_apis/wit/workitems/$Test%20Case?api-version=4.1
Content-Type: application/json-patch+json
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Sample testcase"
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.Steps",
"from": null,
"value": "<steps id=\"0\" last=\"3\"><step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\"><DIV><DIV><P>step1&nbsp;</P></DIV></DIV></parameterizedString><parameterizedString isformatted=\"true\"><DIV><P>&nbsp;0</P></DIV></parameterizedString><description/></step><step id=\"3\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\"><DIV><P>step2&nbsp;</P></DIV></parameterizedString><parameterizedString isformatted=\"true\"><P>&nbsp;pass</P></parameterizedString><description/></step></steps>"
}
]